pillow支持python 2和python 3吗_在Python 3中使用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.

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.

What I did:

I followed the instructions at http://pillow.readthedocs.org/en/latest/index.html to install Pillow v2.4.0 (PIL fork):

I started with:

~$ pip install Pillow

I installed python-setuptools with:

~$ sudo apt-get install python-dev python-setuptools

and also, for python 3:

~$ sudo apt-get install python3-dev python3-setuptools

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 is based on Ubuntu 13.10, but I didn't find a list of prerequisites for any later version)

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'

Any help would be much appreciated.

解决方案

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

Then in the python3.4 interactive shell enter:

>>> from PIL import Image

>>> im = Image.open("someimage.jpg")

>>> im.show()

And voilá, the image appears!

Most helpful sites:

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!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值