我在使用 Pillow 和 Python 3.3.2 时运气不佳,如果能提供一些帮助,我将不胜感激。我的问题是安装 Pillow 后,我无法导入 Image。
我的设置:
我已经安装了 Linux Mint 16(在 HP Pavilion dv7 笔记本电脑上)。
我已经安装了 Python 3.3.2+,它工作正常。
我已经安装了 Python 2.7.5+,它工作正常。
我做了什么:
我按照 http://pillow.readthedocs.org/en/latest/index.html 的说明进行操作安装 Pillow v2.4.0 (PIL fork):
我开始:
~$ pip install Pillow
我安装了 python-setuptools:
~$ sudo apt-get install python-dev python-setuptools
而且,对于python 3:
~$ sudo apt-get install python3-dev python3-setuptools
我因此安装了“Ubuntu 12.04 LTS 的先决条件”:
~$ sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
(Mint 16 基于 Ubuntu 13.10,但我没有找到任何更高版本的先决条件列表)
发生了什么:
使用python 2,
导入图片
工作,我可以打开一个.png图像并显示它。
但是对于 python 3,
'导入图像'
给 '没有名为 Image 的模块' 和
'从 PIL 导入图像'
给 '没有名为 PIL 的模块'
任何帮助将非常感激。
最佳答案
经过大量挖掘,并且由于没有其他答案即将出现,我将回答我自己的问题。这适用于 python3.4 的 Pillow 安装:
$ sudo apt-get install python3-dev python3-setuptools
$ sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \
libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
$ sudo apt-get install python3-pip
$ sudo pip3 install Pillow
$ sudo apt-get install imagemagick
$ sudo ln -s /usr/bin/display /usr/bin/xv
然后在python3.4交互式shell中输入:
>>> from PIL import Image
>>> im = Image.open("someimage.jpg")
>>> im.show()
瞧,图像出现了!
最有帮助的网站:
http://pillow.readthedocs.org/en/latest/installation.html
https://askubuntu.com/questions/427358/install-pillow-for-python-3
Python 3 是一门漂亮的语言,而且它已经实现了,但是安装和使用它的图像库应该不会那么难!
关于python-3.3 - 在 Python 3 中使用 Pillow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23970006/