简体   繁体   English

使用virtualenv或buildout安装PIL的问题

[英]The problem with installing PIL using virtualenv or buildout

When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'. 当我使用easy_install或buildout安装PIL时,其安装方式必须是“导入映像”,而不是“从PIL导入映像”。

However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine. 但是,如果我执行“ apt-get install python-imaging”或使用“ pip -E test_pil install PIL”,则一切正常。

Here are examples of how I trying to install PIL using virtualenv: 以下是我如何尝试使用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

I see, that easy_install pack PIL into the Egg, and PIP does not. 我看到,easy_install将PIL打包到Egg中,而PIP没有。 Same thing with buildbot, it uses eggs. 与buildbot相同,它使用鸡蛋。

How could I install PIL properly, using easy_install or buildout? 如何使用easy_install或buildout正确安装PIL?

The PIL version packaged on pypi (by the author) is incompatible with setuptools and thus not easy_installable. pypi上打包的PIL版本(由作者提供)与setuptools不兼容,因此不是easy_installable。 People have created easy_installable versions elsewhere. 人们在其他地方创建了easy_installable版本。 Currently, you need to specify a find-links URL and use pip get a good package: 当前,您需要指定一个查找链接URL并使用pip获得一个好的软件包:

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

By using pip install with the --no-index you avoid running the risk of finding the PyPI (non-fixed) original of PIL. 通过将pip install--no-index ,可以避免冒发现PIL的PyPI(非固定)原始文件的风险。 If you were to use easy_install , you must use a direct link to the source tarball of a corrected version; 如果要使用easy_install ,则必须使用直接链接到更正版本的源tarball。 easy_install stubbornly still uses the PyPI link over the find-links URL: easy_install仍然顽固地在查找链接URL上使用PyPI链接:

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

To include PIL in a buildout, either specify the egg with the same version pin or use a versions section: 要将PIL包含在扩展中,请使用相同的版本引脚指定egg或使用“版本”部分:

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

[versions]
PIL = 1.1.7

Edit March 2011: Fixes to address the packaging issues have been merged into PIL's development tree now, so this workaround may soon be obsolete. 2011年3月修改:解决包装问题的修补程序现已合并到PIL的开发树中 ,因此此解决方法可能很快就会过时。

Edit February 2013: Just use Pillow and be done with it. 编辑2013年2月:只需使用Pillow即可完成。 :-) Clearly waiting for the original package to be fixed has not paid off. :-)显然,等待原包装修复还没有收到回报。

Use Pillow: the "friendly" PIL fork :-) It offers: 使用枕头:“友好的” PIL叉 :-)它提供:

  • Full setuptools compatibility 全面的设置工具兼容性
  • Faster release cycle 更快的发布周期
  • No image code changes that differ from PIL (ie it aims to track all PIL image code changes, and make none of its own changes without reporting them upstream.) 没有与PIL不同的图像代码更改(即,它旨在跟踪所有PIL图像代码更改,并且在不向上游报告的情况下不进行任何更改)。
  • Windows binaries Windows二进制文件

If PIL ever does exactly what Pillow does, then the fork will die. 如果PIL确实做到了Pillow所做的事情,那么前叉就会死掉。 Until that happens, we have Pillow. 在此之前,我们有Pillow。

DISCLAIMER : I am the fork author, and Pillow was created mainly to make my job easier (although it's great to see other folks using it too). 免责声明 :我是fork的作者,Pillow的创建主要是为了使我的工作更轻松(尽管很高兴看到其他人也使用它)。

EDIT : Pillow 2.0.0 was released on March 15, 2013. It offers Python 3 support and many bug fixes/enhancements. 编辑 :2013年3月15日发布了Pillow 2.0.0。它提供Python 3支持和许多错误修复/增强功能。 While we still attempt to track changes with upstream PIL, (unfortunately or fortunately depending on how you look at it) Pillow has begun to drift away from PIL. 尽管我们仍然尝试跟踪上游PIL的变化,(不幸或幸运的是,取决于您的查看方式)Pillow已开始偏离PIL。

For Ubuntu I found I needed to to install the C headers package for my python version (2.7) 对于Ubuntu,我发现我需要为python版本(2.7)安装C头文件包

sudo apt-get install python2.7-dev

Afterwards, pip install pil worked. 之后, pip install pil工作了。

On Windows, I installed PIL in a virtualenv as follows: 在Windows上,我在virtualenv中安装了PIL,如下所示:

Install PIL in your global python site-packages by executing the .exe from: http://www.pythonware.com/products/pil/ 通过从以下网址执行.exe,将PIL安装在全局python网站程序包中: http : //www.pythonware.com/products/pil/

Then, as a "do it yourself-er", copy the PIL.pth file and PIL directory in C:\\Python25\\Lib\\site-packages to your virtualenv site-packages directory. 然后,作为“自己动手做”,请将C:\\ Python25 \\ Lib \\ site-packages中的PIL.pth文件和PIL目录复制到您的virtualenv site-packages目录中。 Yeah, python is still a "get your hands dirty" environment... 是的,python仍然是一个“让您的手变脏”的环境...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM