我正在尝试使用以下命令安装 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
吗?
如前所述,安装 Xcode 和 Xcode 命令行工具。改用 Pillow,因为 PIL 基本上已经死了。 Pillow 是 PIL 的一个维护分支。
https://pypi.org/project/Pillow/
pip install Pillow
如果您同时安装了两个 Python 并希望为 Python3 安装它:
python3 -m 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
# ln -s /usr/lib/`uname -i`-linux-gnu/libfreetype.so /usr/lib/
的链接
sudo ln -s /usr/include/freetype2 /usr/local/include/freetype
使用 apt install 非常简单,使用此命令即可完成
sudo apt-get install python-PIL
或者
sudo pip install pillow
或者
sudo easy_install pillow
安装
pip install Pillow
然后,只需导入您的文件,例如,
from PIL import Image
我正在使用窗户。它对我有用。
注意:Pillow 是 Python Imaging Library 的功能性替代品。要使用 Pillow 运行现有的 PIL 兼容代码,需要对其进行修改以从 PIL 命名空间而不是全局命名空间导入 Imaging 模块。
即改变:
import Image
至:
from PIL import Image
https://pypi.org/project/Pillow/2.2.1/
from PIL import Image
中阅读名称“PIL”时,我永远猜不到这个库的名称是“Pillow”。我也在 Windows 上,你的解决方案对我有用。
import Image
到 from PIL import Image
pypi.org/project/Pillow/2.2.1
在 Mac OS X 上,使用以下命令:
sudo pip install https://effbot.org/media/downloads/Imaging-1.1.7.tar.gz
brew install libjpeg
我从讨论 here 中得到了答案:
我试过了
pip install --no-index -f http://dist.plone.org/thirdparty/ -U PIL
它奏效了。
pip install --no-index -f http://effbot.org/downloads/ -U PIL --trusted-host effbot.org
我使用这个的原因是因为它是包列出的 URL,并且在 pypi.python.org/pypi/PIL
我认为你在 Mac 上。请参阅How can I install PIL on mac os x 10.7.2 Lion
如果您使用自制软件,您可以使用 brew install pil 安装 PIL。然后,您可能需要将安装目录 ($(brew --prefix)/lib/python2.7/site-packages) 添加到 PYTHONPATH,或者将 PIL 目录本身的位置添加到名为 PIL.pth 的文件中您的站点包目录,内容为:/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 # 构建和安装 python setup.py build sudo python setup.py install # 或者为你安装它而不需要管理员权限:# python setup.py install --user 我跑了上面刚刚(在 OSX 10.7.2 上,使用 XCode 4.2.1 和 System Python 2.7.1)并且它构建得很好,尽管我的环境中的某些东西可能是非默认的。
pil
,但它并没有像 OP 最初尝试的那样通过 pip
进行安装。我发现这些天在网络上大量使用 brew
并不理想。 brew
将安装相当多的开销,具体取决于您希望它执行的操作。所以 pip
可能仍然是 python 模块的最佳选择。
这些天来,每个人都使用 Pillow,一个友好的 PIL 分支,而不是 PIL。
而不是:sudo pip install pil
做:sudo pip install pillow
$ sudo apt-get install python-imaging
$ sudo -H pip install pillow
sudo pip install ...
。这最终可能会破坏您系统的 Python 安装,这可能会影响您系统的应用程序。尝试使用 Anaconda virtual environments、venv 或 Docker。
对于 Ubuntu,PIL 不再工作。我总是得到:
没有找到 PIL 的匹配分布
所以安装python-imaging:
sudo apt-get install python-imaging
我有同样的问题,但安装 python-dev
解决了。
在安装 PIL 之前,运行以下命令:
sudo apt-get install python-dev
然后安装 PIL:
pip install PIL
pip install pil
都会导致 No distributions at all found for PIL
。
我在安装过程中遇到了一些错误。以防万一有人也有这个。尽管我已经坐在管理员用户下,但不是 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
添加“sudo”解决了这个问题,使用 sudo 它可以工作:
~/Documents/mv-server: $ sudo pip install Pillow
对于 CentOS:
yum install python-imaging
我尝试了所有答案,但都失败了。直接从官网获取源码然后build安装成功。
去网站http://www.pythonware.com/products/pil/#pil117点击“Python Imaging Library 1.1.7 Source Kit”下载源码tar xf Imaging-1.1.7.tar.gz cd Imaging-1.1 .7 sudo python setup.py 安装
我用 sudo port install py27-Pillow
搞定了
尝试这个:
sudo pip install PIL --allow-external PIL --allow-unverified PIL
sudo pip install --allow-external --allow-unverified PIL PIL
目前也可以使用。
--allow-external
和 --allow-unverified
均已弃用。 pip install pillow
是正确答案。
首先,您应该运行此 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枕头
在使用 pip
之前搜索包管理器。在 Arch linux 上,您可以通过 pacman -S python2-pillow
获得 PIL
对于 Ubuntu,您可以使用 apt install
安装 PIL:
对于 Python 3 使用:
sudo apt install python3-pil
对于 Python 2 使用:
sudo apt install python-pil
正如 Clarkey252 指出的那样,pil
应该是小写的
apt
是否作为 macOS 的包管理器存在?
不定期副业成功案例分享
clang
错误,但我发现此答案对此有所帮助:stackoverflow.com/a/22322645/16959import Image
的库。有没有办法让 Pillow 提供图像?