python导入pillow模块,使用Pillow导入图像:没有名为'PIL'的模块

Several posts were advising to import Pillow using pip, after having uninstalled both PIL and Pillow, what i did :

python -m pip uninstall Pillow (worked)

python -m pip uninstall PIL (PIL was not installed)

python -m pip install Pillow (worked, i guess it was fine already)

Then, according to these posts, using "from PIL import Image" in python should work. I get the error "ImportError: No module named 'PIL'".

I tried "import Image" and "from Pillow import Image" but none of that works either.

I'm on windows and using python 3.4.1.

Do you know what to do?

Thanks

EDIT : pip had installed Pillow in anaconda3, and not in the python file I use.

I copied/pasted the pillow egg file in site-packages and import PIL now works.

However, from PIL import Image still does not work : i get ImportError: cannot import name 'Image'

EDIT : the problem was that the egg file was not working proerly (i think). I had to add my own python path to the paths in the environment variables, then i could install pillow with pip. But i now have another error.. from PIL import Image returns :

C:\Users\Loic\Documents\Python\pyzo2014a\lib\site-packages\PIL\Image.py in ()

25 #

26

---> 27 from . import VERSION, PILLOW_VERSION, _plugins

28

29 import logging

ImportError: cannot import name 'VERSION'

There is, indeed, no VERSION.py file in the PIL lib. Does that mean i've not installed it correctly? After having defined the python path and installed it with pip in cmd, everything should be fine...

解决方案

I'm on Linux so maybe it doesn't pertain to you, but for me python is Python2.7 and I have to use python3 to get Python3.5

jcomeau@aspire:/usr/src/myturnb$ pip3 install --user Pillow

Collecting Pillow

Downloading Pillow-4.1.0-cp35-cp35m-manylinux1_i686.whl (5.5MB)

100% |████████████████████████████████| 5.5MB 55kB/s

Collecting olefile (from Pillow)

Installing collected packages: olefile, Pillow

Successfully installed Pillow-4.1.0 olefile-0.44

jcomeau@aspire:/usr/src/myturnb$ python3

Python 3.5.2 (default, Jul 5 2016, 11:33:36)

[GCC 5.4.0 20160609] on linux

Type "help", "copyright", "credits" or "license" for more information.

>>> from PIL import Image

>>>

VERSION is defined in __init__.py:

jcomeau@aspire:/usr/src/myturnb$ grep -r VERSION /home/jcomeau/.local/lib/python3.5/site-packages/PIL/ | grep -v '^Binary'

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/__init__.py:VERSION = '1.1.7' # PIL version

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/__init__.py:PILLOW_VERSION = '4.1.0' # Pillow

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/__init__.py:__version__ = PILLOW_VERSION

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/Image.py:from . import VERSION, PILLOW_VERSION, _plugins

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/Image.py: if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/ImageCms.py:VERSION = "1.0.0 pil"

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/ImageCms.py: VERSION, core.littlecms_version,

/home/jcomeau/.local/lib/python3.5/site-packages/PIL/ImageCms.py: sys.version.split()[0], Image.VERSION

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值