我正在尝试使用命令安装PIL (Python映像库):

sudo pip install pil

但我得到了以下信息:

Downloading/unpacking PIL
  You are installing a potentially insecure and unverifiable file. Future versions of pip will default to disallowing insecure files.
  Downloading PIL-1.1.7.tar.gz (506kB): 506kB downloaded
  Running setup.py egg_info for package PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    
Installing collected packages: PIL
  Running setup.py install for PIL
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py
    --- using frameworks at /System/Library/Frameworks
    building '_imaging' extension
    clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -IlibImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o
    unable to execute clang: No such file or directory
    error: command 'clang' failed with exit status 1
    Complete output from command /usr/bin/python -c "import setuptools;__file__='/private/tmp/pip_build_root/PIL/setup.py';exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-AYrxVD-record/install-record.txt --single-version-externally-managed:
    WARNING: '' not a valid package name; please use only.-separated package names in setup.py

running install

running build

.
.
.
.

copying PIL/XVThumbImagePlugin.py -> build/lib.macosx-10.8-intel-2.7

running build_ext

--- using frameworks at /System/Library/Frameworks

building '_imaging' extension

creating build/temp.macosx-10.8-intel-2.7

creating build/temp.macosx-10.8-intel-2.7/libImaging

clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arch x86_64 -pipe -IlibImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.8-intel-2.7/_imaging.o

unable to execute clang: No such file or directory

error: command 'clang' failed with exit status 1

----------------------------------------
Cleaning up…

你能帮我安装PIL吗?


当前回答

这些天,每个人都使用枕头,一个友好的PIL叉子,而不是PIL。

而不是:sudo pip安装pil

做:sudo pip装枕头

$ sudo apt-get install python-imaging
$ sudo -H pip install pillow

其他回答

这对我来说很管用:

apt-get install python-dev
apt-get install libjpeg-dev
apt-get install libjpeg8-dev
apt-get install libpng3
apt-get install libfreetype6-dev
ln -s /usr/lib/i386-linux-gnu/libfreetype.so /usr/lib
ln -s /usr/lib/i386-linux-gnu/libjpeg.so /usr/lib
ln -s /usr/lib/i386-linux-gnu/libz.so /usr/lib

pip install PIL  --allow-unverified PIL --allow-all-external

这些天,每个人都使用枕头,一个友好的PIL叉子,而不是PIL。

而不是:sudo pip安装pil

做:sudo pip装枕头

$ sudo apt-get install python-imaging
$ sudo -H pip install pillow

我猜你在Mac上。看看我如何在Mac os x 10.7.2 Lion上安装PIL

If you use homebrew, you can install the PIL with just brew install pil. You may then need to add the install directory ($(brew --prefix)/lib/python2.7/site-packages) to your PYTHONPATH, or add the location of PIL directory itself in a file called PIL.pth file in any of your site-packages directories, with the contents: /usr/local/lib/python2.7/site-packages/PIL (assuming brew --prefix is /usr/local). Alternatively, you can just download/build/install it from source: # download curl -O -L http://effbot.org/media/downloads/Imaging-1.1.7.tar.gz # extract tar -xzf Imaging-1.1.7.tar.gz cd Imaging-1.1.7 # build and install python setup.py build sudo python setup.py install # or install it for just you without requiring admin permissions: # python setup.py install --user I ran the above just now (on OSX 10.7.2, with XCode 4.2.1 and System Python 2.7.1) and it built just fine, though there is a possibility that something in my environment is non-default.

安装

pip install Pillow

然后,导入你的文件,

from PIL import Image

我用的是windows。这对我很有用。

注意: Pillow是Python Imaging的功能性替代品 图书馆。要使用Pillow运行现有的与pil兼容的代码,请使用 需要修改从PIL导入Imaging模块 命名空间,而不是全局命名空间。

即改变:

导入图片

to:

来自PIL import Image

https://pypi.org/project/Pillow/2.2.1/

对于Ubuntu,你可以使用apt install安装PIL:

对于Python 3,请使用:

sudo apt install python3-pil

对于Python 2使用:

sudo apt install python-pil

哪里pil应该小写Clarkey252指出