有几个帖子建议在卸下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)
然后,根据这些帖子,使用"来自PIL导入Image"在python应该工作。我收到错误" ImportError:没有名为' PIL'"的模块。
我试过"导入图片"和来自Pillow的"导入图像"但这一切都不起作用。 我在Windows上使用python 3.4.1。
你知道该怎么办吗? 感谢
编辑:pip已经在anaconda3中安装了Pillow,而不是在我使用的python文件中。 我在网站包中复制/粘贴了枕头鸡蛋文件,import PIL
现在有效。
但是,from PIL import Image
仍然不起作用:我得到ImportError: cannot import name 'Image'
编辑:问题是鸡蛋文件没有正常工作(我认为)。我不得不将自己的python路径添加到环境变量中的路径,然后我可以用pip安装枕头。但我现在有另一个错误.. 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 lib中确实没有VERSION.py文件。这是否意味着我没有正确安装?在定义了python路径并在cmd中使用pip安装它之后,一切都应该没问题......
答案 0 :(得分:1)
我在Linux上也许它不适合你,但对我来说python
是Python2.7而我必须使用python3
来获取Python3.5 < / p>
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
在__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