在卸载了PIL和Pillow之后,有几篇文章建议使用pip导入Pillow,我这样做了:
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)
然后,根据这些帖子,在python中使用"from PIL import Image“应该是可行的。我收到错误消息"ImportError:没有名为‘PIL’的模块“。
我尝试了“导入图像”和“从枕头导入图像”,但都不起作用。我在windows上使用python 3.4.1。
你知道该怎么做吗?谢谢
编辑: pip在anaconda3中安装了Pillow,而不是在我使用的python文件中。我在site-packages中复制/粘贴了pillow egg文件,现在import PIL
可以工作了。但是,from PIL import Image
仍然不起作用:我得到了ImportError: cannot import name 'Image'
编辑:问题在于(我认为) egg文件不能正常工作。我必须将我自己的python路径添加到环境变量中的路径中,然后才能使用pip安装pillow。但是我现在又犯了一个错误..from PIL import Image
返回:
C:\Users\Loic\Documents\Python\pyzo2014a\lib\site-packages\PIL\Image.py in <module>()
25 #
26
---> 27 from . import VERSION, PILLOW_VERSION, _plugins
28
29 import logging
ImportError: cannot import name 'VERSION'
实际上,在PIL库中没有VERSION.py文件。这是否意味着我没有正确安装它?在定义了python路径并在cmd中使用pip安装它之后,一切都应该很好了……
发布于 2017-04-23 04:25:33
我使用的是Linux,所以它可能不适合您,但对我来说,python
是Python2.7,我必须使用python3
才能获得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
>>>
在__init__.py
中定义了VERSION
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
https://stackoverflow.com/questions/43560898
复制相似问题