【问题标题】:Using Pillow with Python 3在 Python 3 中使用 Pillow
【发布时间】:2014-07-21 02:57:18
【问题描述】:

我在使用 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 的模块'

任何帮助将不胜感激。

【问题讨论】:

标签: python-3.3 pillow


【解决方案1】:

经过大量挖掘,由于没有其他答案,我将回答我自己的问题。这适用于 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中输入:

>>> 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 是一门漂亮的语言,而且它已经实现了,但安装和使用它的图像库应该不会那么难!

【讨论】:

  • 对我来说它是 pip3.2 安装,如果其他人也有同样的问题,就像我一样
  • 在 Ubuntu 15.04 中执行 sudo apt-get install python3-dev python3-setuptools 然后在 virtualenv 中安装枕头就足够了。
  • 更新:sudo apt-get install libtiff5-dev libjpeg62-turbo-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev k8.5-dev
  • @Tom 浏览所有依赖项并没有什么坏处。它会告诉你什么时候已经安装并跳过它。
【解决方案2】:

你得到这个错误的原因是你没有正确安装 python 解释器或者你的 pip 文件夹放错了位置。 只需下载 [新解释器] (https://www.python.org/downloads/)!你可以走了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-25
    • 2016-12-08
    • 2022-01-22
    • 2013-12-20
    • 2020-09-21
    • 2022-07-11
    • 2021-01-19
    相关资源
    最近更新 更多