为什么Python不能从PIL导入Image?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26505958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why can't Python import Image from PIL?
提问by Betohaku
The single line that I am trying to run is the following:
我试图运行的单行如下:
from PIL import Image
However simple this may seem, it gives an error:
无论这看起来多么简单,它都会产生一个错误:
Traceback (most recent call last):
File "C:\...14-10-22_12-49.py", line 1, in <module>
from PIL import Image
File "C:\pyzo2014a\lib\site-packages\PIL\Image.py", line 29, in <module>
from PIL import VERSION, PILLOW_VERSION, _plugins
ImportError: cannot import name 'VERSION'
In case that's helpful, I installed pillow from https://pypi.python.org/pypi/Pillow/2.6.1(file Pillow-2.6.1.win-amd64-py3.4.exe) before running this (before that there was already som PILinstall, which I uninstalled). The script is run in Pyzo with Python version 3.4.1.
如果这有帮助,我在运行之前从https://pypi.python.org/pypi/Pillow/2.6.1(file Pillow-2.6.1.win-amd64-py3.4.exe)安装了枕头(在此之前已经PIL安装了 som ,我卸载了它)。该脚本在 Python 版本 3.4.1 的 Pyzo 中运行。
What is going wrong, how can I import Image?
出了什么问题,我该如何导入Image?
回答by selfboot
The current free version is PIL 1.1.7. This release supports Python 1.5.2 and newer, including 2.5 and 2.6. A version for 3.X will be released later.
当前的免费版本是 PIL 1.1.7。此版本支持 Python 1.5.2 和更新版本,包括 2.5 和 2.6。3.X 的版本将在稍后发布。
Your python version is 3.4.1, PIL do not support!
你的python版本是3.4.1,PIL不支持!
回答by Trent
I had the same error. Here was my workflow. I first installed PIL (not Pillow) using
我有同样的错误。这是我的工作流程。我首先安装了 PIL(不是 Pillow)使用
pip install --no-index -f https://dist.plone.org/thirdparty/ -U PIL
Then I found Pillow and installed it using
然后我找到 Pillow 并使用它安装了它
pip install Pillow
What fixed my issues was uninstalling both and reinstalling Pillow
解决我的问题是卸载并重新安装 Pillow
pip uninstall PIL
pip uninstall Pillow
pip install Pillow
回答by Vivien G.
In Ubuntu OS, I solved it with the followings commands
在 Ubuntu OS 中,我使用以下命令解决了它
pip install Pillow
apt-get install python-imaging
And sorry, dont ask me why, it's up to me ;-)
对不起,不要问我为什么,这取决于我;-)
回答by Omar
All the answers were great however what did it for me was a combination of uninstalling Pillow
所有的答案都很棒但是对我来说是卸载 Pillow 的组合
pip uninstall Pillow
Then installing whatever packages you need e.g.
然后安装您需要的任何软件包,例如
sudo apt-get -y install python-imaging
sudo apt-get -y install zlib1g-dev
sudo apt-get -y install libjpeg-dev
And then using easy_install to reinstall Pillow
然后使用easy_install重新安装Pillow
easy_install Pillow
Hope this helps others
希望这对其他人有帮助
回答by Guydangerous99
do from PIL import Image, ImageTk
做 from PIL import Image, ImageTk
回答by keshvari
If you did all and it didn't work again like mien, do this copy Image.pyand ImageTk.pyfrom /usr/lib/python3/dist-packages/PILon ubuntu and C:/Users/yourComputerName/AppData/Local/Programs/Python/Python36/Lib/PILon windows to your projects directory and just import them!
如果你做了所有的事情并且它没有像 mien 那样再次工作,请从ubuntu 和C:/Users/yourComputerName/AppData/Local 上的/usr/lib/python3/dist-packages/PIL复制Image.py和ImageTk.pyWindows 上的/Programs/Python/Python36/Lib/PIL到您的项目目录,然后导入它们!
回答by theeastcoastwest
FWIW, the following worked for me when I had this same error:
FWIW,当我遇到同样的错误时,以下对我有用:
pip install --upgrade --force-reinstall pillow
回答by Nijanth Anand
I had the same issue, and did this to fix it:
我有同样的问题,并这样做来解决它:
In command prompt
pip install Pillow ##Ensure that you use
from PIL import Image
在命令提示符中
pip install Pillow ##确保您使用
from PIL import Image
Iin Imagehas to be capital. That was the issue in my case.
IinImage必须是资本。这就是我的问题。
回答by nikhil swami
Any library/package you import must have its dependencies and subordinate parts in the same python directory. in linux if you
您导入的任何库/包都必须在同一个 python 目录中具有其依赖项和从属部分。在 linux 中,如果你
Python3.x -m pip install <your_library_name_without_braces>
Python3.x -m pip install <your_library_name_without_braces>
what happens is, it installs on the default python. so first make sure that only 1 python 2.x and 1 python 3.x versions are on your pc.
发生的情况是,它安装在默认的 python 上。所以首先确保你的电脑上只有 1 个 python 2.x 和 1 个 python 3.x 版本。
If you want to successfully install matplotlibyou need these lines,
如果你想成功安装 matplotlib,你需要这些行,
python -m pip install matplotlib pillow numpy pandas
the last 2 were auxiliary libs, and must have.
最后两个是辅助库,必须有。

