[英]Import Image using Pillow : No module named 'PIL'
Several posts were advising to import Pillow using pip, after having uninstalled both PIL and Pillow, what i did : 在卸载了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)
Then, according to these posts, using "from PIL import Image" in python should work. 然后,根据这些帖子,可以在python中使用“ from PIL import Image”。 I get the error "ImportError: No module named 'PIL'".
我收到错误“ ImportError:没有名为'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.
我在Windows上并使用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. 编辑:pip已在anaconda3中安装了Pillow,而不是在我使用的python文件中安装了Pillow。 I copied/pasted the pillow egg file in site-packages and
import PIL
now works. 我将枕头蛋文件复制/粘贴到站点程序包中,然后
import PIL
现在可以使用了。 However, from PIL import Image
still does not work : i get ImportError: cannot import name 'Image'
但是,
from PIL import Image
仍然不起作用:我得到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.
我必须在环境变量的路径中添加自己的python路径,然后才能使用pip安装枕头。 But i now have another error..
from PIL import Image
returns : 但是我现在有另一个错误..
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'
There is, indeed, no VERSION.py file in the PIL lib. 实际上,PIL库中没有VERSION.py文件。 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...
在定义了python路径并在cmd中将其与pip一起安装之后,一切都应该没问题了...
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 我在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
>>>
VERSION
is defined in __init__.py
: 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.