为什么Python不能从PIL导入图像?

时间:2022-11-08 00:25:31

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:\...\2014-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 PIL install, which I uninstalled). The script is run in Pyzo with Python version 3.4.1.

如果这是有用的,我在运行这个之前安装了https://pypi.python.org/pypi/Pillow/2.6.1(文件pillow -2.6.1.win-amd64-py3.4.exe)的枕头(在此之前,已经安装了som PIL安装,我卸载了它)。该脚本在Pyzo中运行,Python版本为3.4.1。

What is going wrong, how can I import Image?

哪里出了问题,我如何导入图像?

7 个解决方案

#1


16  

I had the same error. Here was my workflow. I first installed PIL (not Pillow) using

我犯了同样的错误。这是我的工作流程。我首先使用的是PIL(而不是枕头)。

pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

Then I found Pillow and installed it using

然后我找到了枕头并安装了它。

pip install Pillow

What fixed my issues was running uninstalling both and reinstalling Pillow

我的问题解决的是卸载和重新安装枕头!

pip uninstall PIL
pip uninstall Pillow
pip install Pillow

#2


4  

If you use Anaconda, you may try:

如果你使用蟒蛇,你可以试试:

conda install Pillow

Example

例子

#3


3  

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稍后会被释放。

Python Imaging Library (PIL)

Python成像库(公益诉讼)

Your python version is 3.4.1, PIL do not support!

您的python版本是3.4.1,PIL不支持!

#4


3  

In Ubuntu OS, I solved it with the followings commands

在Ubuntu操作系统中,我用下面的命令来解决它。

pip install Pillow
apt-get install python-imaging

And sorry, dont ask me why, it's up to me ;-)

对不起,不要问我为什么,这取决于我;-)

#5


1  

All the answers were great however what did it for me was a combination of uninstalling 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重新安装枕头。

easy_install Pillow

Hope this helps others

希望这可以帮助其他人

#6


0  

do from PIL import Image, ImageTk

从PIL import Image, ImageTk ?

#7


0  

If you did all and it didn't work again like mien, do this copy Image.py and ImageTk.py from /usr/lib/python3/dist-packages/PIL on ubuntu and C:/Users/yourComputerName/AppData/Local/Programs/Python/Python36/Lib/PIL on windows to your projects directory and just import them!

如果你做了所有的事情,它又不像mien那样工作了,那就复制图片。py和ImageTk。从/usr/lib/python3/dist-package /PIL在ubuntu和C:/用户/你的计算机名称/AppData/本地/程序/Python/Python36/Lib/PIL on windows到你的项目目录,然后导入它们!

#1


16  

I had the same error. Here was my workflow. I first installed PIL (not Pillow) using

我犯了同样的错误。这是我的工作流程。我首先使用的是PIL(而不是枕头)。

pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL

Then I found Pillow and installed it using

然后我找到了枕头并安装了它。

pip install Pillow

What fixed my issues was running uninstalling both and reinstalling Pillow

我的问题解决的是卸载和重新安装枕头!

pip uninstall PIL
pip uninstall Pillow
pip install Pillow

#2


4  

If you use Anaconda, you may try:

如果你使用蟒蛇,你可以试试:

conda install Pillow

Example

例子

#3


3  

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稍后会被释放。

Python Imaging Library (PIL)

Python成像库(公益诉讼)

Your python version is 3.4.1, PIL do not support!

您的python版本是3.4.1,PIL不支持!

#4


3  

In Ubuntu OS, I solved it with the followings commands

在Ubuntu操作系统中,我用下面的命令来解决它。

pip install Pillow
apt-get install python-imaging

And sorry, dont ask me why, it's up to me ;-)

对不起,不要问我为什么,这取决于我;-)

#5


1  

All the answers were great however what did it for me was a combination of uninstalling 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重新安装枕头。

easy_install Pillow

Hope this helps others

希望这可以帮助其他人

#6


0  

do from PIL import Image, ImageTk

从PIL import Image, ImageTk ?

#7


0  

If you did all and it didn't work again like mien, do this copy Image.py and ImageTk.py from /usr/lib/python3/dist-packages/PIL on ubuntu and C:/Users/yourComputerName/AppData/Local/Programs/Python/Python36/Lib/PIL on windows to your projects directory and just import them!

如果你做了所有的事情,它又不像mien那样工作了,那就复制图片。py和ImageTk。从/usr/lib/python3/dist-package /PIL在ubuntu和C:/用户/你的计算机名称/AppData/本地/程序/Python/Python36/Lib/PIL on windows到你的项目目录,然后导入它们!