首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Pillow导入图像:没有名为'PIL‘的模块

使用Pillow导入图像:没有名为'PIL‘的模块
EN

Stack Overflow用户
提问于 2017-04-22 23:18:13
回答 1查看 3.7K关注 0票数 0

在卸载了PIL和Pillow之后,有几篇文章建议使用pip导入Pillow,我这样做了:

代码语言:javascript
运行
复制
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返回:

代码语言:javascript
运行
复制
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安装它之后,一切都应该很好了……

EN

回答 1

Stack Overflow用户

发布于 2017-04-23 04:25:33

我使用的是Linux,所以它可能不适合您,但对我来说,python是Python2.7,我必须使用python3才能获得Python3.5

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43560898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档