Python 使用 pip 安装 PIL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20060096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:24:28  来源:igfitidea点击:

Installing PIL with pip

pythonpython-2.7installationpippython-imaging-library

提问by user3006710

I am trying to install PIL (the Python Imaging Library) using the command:

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

sudo pip install pil

but I get the following message:

但我收到以下消息:

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…

Could you please help me to install PIL??

你能帮我安装PIL吗??

回答by KGo

I take it you're on Mac. See How can I install PIL on mac os x 10.7.2 Lion

我认为你在使用 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.pthfile in any of your site-packages directories, with the contents:

/usr/local/lib/python2.7/site-packages/PIL

(assuming brew --prefixis /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.

[homebrew]: http://mxcl.github.com/homebrew/"Homebrew"

如果你使用 [homebrew][],你可以只用brew install pil. 然后,您可能需要将安装目录 ( $(brew --prefix)/lib/python2.7/site-packages)添加到 PYTHONPATH,或者将 PIL 目录本身的位置添加到PIL.pth任何站点包目录中名为file 的文件中,其内容为:

/usr/local/lib/python2.7/site-packages/PIL

(假设brew --prefix/usr/local)。

或者,您可以从源代码下载/构建/安装它:

# 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

我刚刚运行了上面的程序(在 OSX 10.7.2 上,使用 XCode 4.2.1 和 System Python 2.7.1)并且它构建得很好,尽管我的环境中的某些东西可能是非默认的。

[自制]:http: //mxcl.github.com/homebrew/“自制”

回答by FogleBird

  1. Install Xcode and Xcode Command Line Tools as mentioned.
  2. Use Pillow instead, as PIL is basically dead. Pillow is a maintained fork of PIL.
  1. 如上所述安装 Xcode 和 Xcode 命令行工具。
  2. 改用 Pillow,因为 PIL 基本上已经死了。Pillow 是 PIL 的维护叉。

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

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

pip install Pillow

If you have both Pythons installed and want to install this for Python3:

如果您安装了两个 Python 并且想为 Python3 安装它:

python3 -m pip install Pillow

回答by Kedar.Aitawdekar

I'm having the same problem, but it gets solved with installation of python-dev.

我遇到了同样的问题,但安装python-dev.

Before installing PIL, run following command:

在安装 PIL 之前,运行以下命令:

sudo apt-get install python-dev

Then install PIL:

然后安装PIL:

pip install PIL

回答by Ryan Lee

On Mac OS X, use this command:

在 Mac OS X 上,使用以下命令:

sudo pip install https://effbot.org/media/downloads/Imaging-1.1.7.tar.gz

回答by madjardi

This works for me:

这对我有用:

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

回答by Alexandre Sim?es

I nailed it by using sudo port install py27-Pillow

我用钉子钉住了它 sudo port install py27-Pillow

回答by imos

For CentOS:

对于 CentOS:

yum install python-imaging

回答by Chet

There's another Python package tool called conda. Conda is preferred (I believe) over pip when there are libraries that need to install C++ and other bindings that aren't pure Python. Conda includes pip in its installation as well so you can still use pip, but you also get the benefits of conda.

还有另一个名为conda. 当存在需要安装 C++ 和其他非纯 Python 绑定的库时,Conda 比 pip 更受欢迎(我相信)。Conda 在其安装中也包含 pip,因此您仍然可以使用 pip,但您也可以获得 conda 的好处。

Conda also installs IPython, pil, and many other libraries by default. I think you'll like it.

默认情况下,Conda 还安装IPython、 pil 和许多其他库。我想你会喜欢的。

回答by Denis Kutlubaev

I had some errors during installation. Just in case somebody has this too. Despite that I already was sitting under admin user, but not root.

我在安装过程中遇到了一些错误。以防万一有人也有这个。尽管如此,我已经坐在管理员用户下,但不是 root。

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/PIL'

Storing debug log for failure in /Users/wzbozon/Library/Logs/pip.log

Adding "sudo" solved the problem, with sudo it worked:

添加“sudo”解决了这个问题,使用 sudo 就可以了:

~/Documents/mv-server: $ sudo pip install Pillow

回答by ismailsunni

I got the answer from a discussion here:

我从这里的讨论中得到了答案:

I tried

我试过

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

and it worked.

它奏效了。