python-3.3 - 在 Python 3 中使用 Pillow

标签 python-3.3 pillow

我在使用 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/

相关文章:

python - Tkinter 窗口与线程不能很好地配合

plugins - uwsgi python3插件不起作用

python - 为什么打印 py_varo 而不是文本框中的值?

Python 3.3.2 在 If-else 中使用 ":"语法错误

python - 使用PIL python来计算灰度等级的errorType

python - 如何在 Spyder(Anaconda 3) 上安装 PIL?

python - 如何在不写/读的情况下在 Python 中执行 JPEG 压缩

django - 如何在 Django 上将 Pillow 处理后的图像上传到 S3?

python - For 循环运行直到达到变量值

python-3.x - PIL ImageTK 未在 py2app 应用程序包中加载图像