关于python:用pip安装PIL

Installing PIL with pip

我正在尝试使用以下命令安装PIL(Python Imaging Library):

1
sudo pip install pil

但我收到以下消息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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('

', '
'), __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吗?


  • 如上所述安装Xcode和Xcode命令行工具。
  • 使用Pillow,因为PIL基本上已经死了。枕头是PIL的维护叉。
  • https://pypi.python.org/pypi/Pillow/2.2.1

    1
    pip install Pillow

    如果你安装了两个Pythons并想为Python3安装它:

    1
    python3 -m pip install Pillow


    这对我有用:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    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


    使用apt install非常简单,使用此命令来完成它

    1
    sudo apt-get install python-PIL

    要么

    1
    sudo pip install pillow

    要么

    1
    sudo easy_install pillow


    在Mac OS X上,使用此命令:

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


    您应按照此处所述进行安装:

    1
    pip install image

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

    我试过了

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

    它起作用了。


    对于Ubuntu,PIL不再工作了。我总是得到:

    No matching distribution found for PIL

    所以安装python-imaging:

    1
    sudo apt-get install python-imaging

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

    而不是:sudo pip install pil

    做:sudo pip install pillow

    1
    2
    $ 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:

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

    (assuming brew --prefix is /usr/local).

    Alternatively, you can just download/build/install it from source:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # 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"


    我遇到了同样的问题,但是通过安装python-dev解决了这个问题。

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

    1
    sudo apt-get install python-dev

    然后安装PIL:

    1
    pip install PIL


    对于CentOS:

    1
    yum install python-imaging

    我尝试了所有的答案,但是发了故事。
    直接从官方网站获取源代码,然后构建安装成功。

  • 转到网站http://www.pythonware.com/products/pil/#pil117
  • 单击"Python Imaging Library 1.1.7 Source Kit"下载源代码
  • tar xf Imaging-1.1.7.ta??r.gz
  • cd Imaging-1.1.7
  • sudo python setup.py安装

  • 安装过程中出现了一些错误。以防有人也这样做。尽管我已经坐在管理员用户下,但不是root用户。

    1
    2
    3
    4
    5
    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

    添加"sudo"解决了这个问题,sudo工作正常:

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

    (窗口)如果Pilow不起作用,请尝试下载http://www.pythonware.com/products/pil/


    试试这个:

    1
    sudo pip install PIL --allow-external PIL --allow-unverified PIL


    • 首先,您应该运行此sudo apt-get build-dep python-imaging,它将为您提供所需的所有依赖项

    • 然后运行sudo apt-get update && sudo apt-get -y upgrade

    • 接下来是sudo apt-get install python-pip

    • 然后最后安装Pil pip install pillow


    我用sudo port install py27-Pillow把它钉了下来


    在使用pip之前搜索包管理器。在Arch linux上你可以通过pacman -S python2-pillow获得PIL


    安装

    1
    pip install Pillow

    然后,就像你的文件一样,

    1
    from PIL import Image

    我正在使用Windows。它对我有用。


    还有另一个名为conda的Python包工具。当有些库需要安装C ++和其他不是纯Python的绑定时,Conda是首选(我相信)。 Conda在其安装中也包括pip,所以你仍然可以使用pip,但你也可以获得conda的好处。

    Conda还默认安装了IPython,pil和许多其他库。我想你会喜欢它。