使用枕头导入图像:没有名为' PIL'

时间:2017-04-22 15:18:13

标签: python image python-imaging-library python-3.4 pillow

有几个帖子建议在卸下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安装它之后,一切都应该没问题......

1 个答案:

答案 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