Installing Pillow and PIL

感情迁移 提交于 2019-12-11 04:05:11

问题


I have Ubuntu 12.04 (Precise Pangolin) installed and some package installed, PIL. Now I want to use Pillow, but that cannot be installed at the same time as PIL.

I looked at virtualenv, but there are other packages I don't want to have to install.

Is there another way to set this up without the clash?


回答1:


You should install Pillow from the Git clone with (choose /opt/pillow as you want):

python setup.py install --prefix /opt/pillow

And then it include in your code,

import sys
sys.path.insert(0, "/opt/pillow")

before doing the import of Pillow with

from PIL import Image

This will search the /opt/pillow directory first and anything without that insert will never see Pillow.




回答2:


I set up a fork of Pillow that properly masquerades its package name arbitrarily, when built with the environment variable PILLOW_NAME set (e.g. PILLOW_NAME=PIL). So you can install Pillow under the PIL package name like this:

$ PILLOW_NAME=PIL pip install -U https://github.com/fish2000/Pillow/archive/master.zip

... If you wish, you can check the custom package-name installation like so:

$ pip freeze | grep -i pil
[...]
PIL==2.3.0
$ python -c 'from PIL import Image' && echo "PIL installed OK"
PIL installed OK

If you have this Pillow fork installed under the name “PIL” you’ll be able to install packages that call for PIL as a requirement. Bear in mind: this will not help you if those packages rely on old PIL-specific behavior (e.g. import Image and friends) – but it will get you past the name issue when installing packages that specifically require PIL.



来源:https://stackoverflow.com/questions/20017319/installing-pillow-and-pil

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!