在Python 3中使用Pillow [英] Using Pillow with Python 3
问题描述
我在Python 3.3.2中使用Pillow的运气并不好,我很感谢您的帮助.我的问题是安装枕头后,我无法导入图像.
I'm not having much luck using Pillow with Python 3.3.2 and I'd be grateful for some help. My problem is that after installing Pillow, I can't import Image.
我的设置: 我已经安装了Linux Mint 16(在HP Pavilion dv7笔记本电脑上). 我已经安装了Python 3.3.2+,并且工作正常. 我已经安装了Python 2.7.5+,并且运行良好.
My setup: I've got Linux Mint 16 installed (on an HP Pavilion dv7 laptop). I've got Python 3.3.2+ installed, and it's working fine. I've got Python 2.7.5+ installed, and it's working fine.
我做了什么: 我按照 http://pillow.readthedocs.org/en/latest/index.html 上的说明进行操作安装Pillow v2.4.0(PIL前叉):
What I did: I followed the instructions at http://pillow.readthedocs.org/en/latest/index.html to install Pillow v2.4.0 (PIL fork):
我从开始:
~$ pip install Pillow
我安装了python-setuptools:
I installed python-setuptools with:
~$ sudo apt-get install python-dev python-setuptools
,对于python 3:
and also, for python 3:
~$ sudo apt-get install python3-dev python3-setuptools
我因此安装了在Ubuntu 12.04 LTS上的先决条件":
I installed "prerequisites on Ubuntu 12.04 LTS" thus:
~$ 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, 导入图片" 给了没有名为图片的模块" ,并且 从PIL导入图像" 给了没有名为PIL的模块"
What happened: With python 2, import image worked and I could open a .png image and show it. But with python 3, 'import image' gave 'no module named Image' and 'from PIL import Image' gave 'no module named PIL'
任何帮助将不胜感激.
推荐答案
经过大量挖掘,并且由于没有其他答案,我将回答我自己的问题.这适用于python3.4的枕头安装:
After much digging, and since there's been no other answer forthcoming, I'll answer my own question. This works for the pillow installation for python3.4:
$ 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中输入:
Then in the python3.4 interactive shell enter:
>>> 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 is a beautiful language, and it's getting there, but installing and using its imaging library shouldn't be so hard to do!
这篇关于在Python 3中使用Pillow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!