【问题标题】:The problem with installing PIL using virtualenv or buildout使用 virtualenv 或 buildout 安装 PIL 的问题
【发布时间】:2011-01-29 22:16:52
【问题描述】:

当我使用 easy_install 或 buildout 安装 PIL 时,它会以这样的方式安装,我必须执行“import Image”,而不是“from PIL import Image”。

但是,如果我执行“apt-get install python-imaging”或使用“pip -E test_pil install PIL”,一切正常。

以下是我尝试使用 virtualenv 安装 PIL 的示例:

# virtualenv --no-site-packages test_pil
# test_pil/bin/easy_install PIL
# test_pil/bin/python
Python 2.5.1 (r251:54863, Feb  6 2009, 19:02:12) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL

我明白了,easy_install 将 PIL 打包到 Egg 中,而 PIP 没有。 buildbot 也一样,它使用鸡蛋。

如何使用 easy_install 或 buildout 正确安装 PIL?

【问题讨论】:

    标签: python python-imaging-library easy-install buildout pip


    【解决方案1】:

    pypi(作者)打包的 PIL 版本与 setuptools 不兼容,因此无法轻松安装。人们已经在其他地方创建了 easy_installable 版本。目前,您需要指定一个 find-links URL 并使用pip 获取一个好的包:

    pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
    

    通过将pip install--no-index 一起使用,您可以避免冒着找到PIL 的PyPI(非固定)原件的风险。如果您要使用easy_install,则必须使用指向更正版本的源压缩包的直接链接; easy_install 仍然顽固地在 find-links URL 上使用 PyPI 链接:

    easy_install http://dist.plone.org/thirdparty/PIL-1.1.7.tar.gz
    

    要在构建中包含 PIL,请使用相同的版本引脚指定 egg 或使用版本部分:

    [buildout]
    parts =
    find-links =
        http://dist.plone.org/thirdparty/
    eggs =
        PIL
    versions = versions
    
    [versions]
    PIL = 1.1.7
    

    2011 年 3 月编辑:解决打包问题的修复程序现已合并到 PIL's development tree,因此此解决方法可能很快就会过时。

    2013 年 2 月编辑:只需使用 Pillow 即可。 :-) 显然等待原包装修复没有得到回报。

    【讨论】:

    • 作者是否收到通知,以便在 pypi 上也得到修复?
    • 我尝试了您示例中显示的版本,但仍然遇到同样的问题。我最终使用了 pythonware 网站上的安装程序,然后将 PIL 目录和 PIL.pth 文件复制到了 virtualenv,它为我解决了这个问题。
    • Pillow 是 PIL 的一个 fork,目的是修复包装,它似乎是一个替代品。
    • 为我解决了这个问题。只需确保先删除损坏的 PIL。
    • @MartijnPieters 六个月后,该更改仍未发布,这是支持分叉恕我直言的一个很好的理由。此外,Pillow 基本上完成了与上面接受的答案相同的事情,而无需指定备用索引。
    【解决方案2】:

    使用Pillow: the "friendly" PIL fork :-) 它提供:

    • 完整的 setuptools 兼容性
    • 更快的发布周期
    • 没有与 PIL 不同的图像代码更改(即,它旨在跟踪所有 PIL 图像代码更改,并且在不向上游报告的情况下不进行任何更改。)
    • Windows 二进制文件

    如果 PIL 完全按照 Pillow 所做的那样做,那么叉子就会死掉。在此之前,我们有 Pillow。

    免责声明:我是 fork 作者,创建 Pillow 主要是为了让我的工作更轻松(尽管很高兴看到其他人也在使用它)。

    编辑:Pillow 2.0.0 于 2013 年 3 月 15 日发布。它提供 Python 3 支持和许多错误修复/增强功能。虽然我们仍在尝试跟踪上游 PIL 的变化,(不幸或幸运取决于你如何看待它)Pillow 已经开始偏离 PIL。

    【讨论】:

    • 感谢您的工作!我也试图让我的金字塔结构与 PIL 一起工作,但现在我发现了这个讨论,我用 Pillow 代替了它,它奏效了。 :-)
    • 感谢枕头@aclark!在我每次构建新机器时与 PIL 苦苦挣扎至少一年之后,并且总是在 Ubuntu 上使用 virtualenv、buildout 和 setuptools 支持 JPEG 和 PNG 时遇到问题,我找到了 Pillow!现在,只是一个 setuptools 定义,它就可以工作了。一千多谢!
    • 我认为这不再是必要的了——它现在可以与设置工具一起使用,对吧?
    • @Ranman 这取决于您所说的“使用 setuptools”是什么意思。如果有帮助的话,自 2010 年分叉以来没有新的 PIL 版本。
    • 访问Image模块的标准方式是from PIL import Image。但在 PIL 中也有 import Image,在很多地方我都发现了这一点。我在 Windows 上有 Pillow 3.0.0,它不支持裸 import Image。如何在不破解依赖代码的情况下解决它?
    【解决方案3】:

    对于 Ubuntu,我发现我需要为我的 python 版本 (2.7) 安装 C 头文件包

    sudo apt-get install python2.7-dev

    之后,pip install pil 工作了。

    【讨论】:

    • 我在尝试在 Ubuntu virtualenv 中安装 PIL 时还需要 Python.h 文件,这已解决!
    【解决方案4】:

    在 Windows 上,我在 virtualenv 中安装了 PIL,如下所示:

    通过从以下位置执行 .exe 在您的全局 python 站点包中安装 PIL: http://www.pythonware.com/products/pil/

    然后,作为“自己动手”,将 C:\Python25\Lib\site-packages 中的 PIL.pth 文件和 PIL 目录复制到您的 virtualenv site-packages 目录。是的,python 仍然是一个“弄脏你的手”的环境......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-07
      • 1970-01-01
      • 1970-01-01
      • 2011-12-20
      • 1970-01-01
      • 2011-09-02
      相关资源
      最近更新 更多