在今天尝试编写使用 PIL 的 Python 脚本的过程中,我发现我的本地机器上似乎没有它(OS X 10.5.8,默认安装 2.5 Python)。
所以我跑:
easy_install --prefix=/usr/local/python/ pil
它抱怨 /usr/local/python/lib/python2.5/site-packages 尚不存在,所以我创建它,然后再试一次,得到这个:
测试失败:/usr/local/python//lib/python2.5/site-packages 不支持 .pth 文件错误:安装目录或 PYTHONPATH 错误
您正在尝试将软件包安装到不在 PYTHONPATH 上且 Python 不会从中读取“.pth”文件的目录中。您指定的安装目录(通过 --install-dir、--prefix 或 distutils 默认设置)是:
/usr/local/python//lib/python2.5/site-packages
并且您的 PYTHONPATH 环境变量当前包含:
''
好的,很公平——我没有做任何事情来设置路径。所以我在 ~/.bash_profile 中添加了一个快速行:
PYTHONPATH="$PYTHONPATH:/usr/local/python/lib/python2.5"
和source
它,然后再试一次。
相同的错误信息。
鉴于 PYTHONPATH 已明确设置,这有点奇怪;我可以echo $PYTHONPATH
回来:/usr/local/python/lib/python2.5
。我决定从内部检查包含路径的样子:
import sys
print "\n".join(sys.path)
产生:
/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5 /System/Library/Frameworks/Python.framework /Versions/2.5/lib/python2.5/plat-darwin /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/plat-mac /System/Library/Frameworks/Python.framework/Versions /2.5/lib/python2.5/plat-mac/lib-scriptpackages /System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python /System/Library/Frameworks/Python.framework/Versions/2.5 /lib/python2.5/lib-tk /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/lib-dynload /Library/Python/2.5/site-packages /System/Library/Frameworks /Python.framework/Versions/2.5/Extras/lib/python/PyObjC
其中/usr/local/python/yadda/yadda
明显缺失。
不知道我应该在这里做什么。如何让 python 将此位置识别为包含路径?
更新
正如 Sven Marnach 建议的那样,我忽略了导出 PYTHONPATH。我已经纠正了这个问题,现在当我sys.path
从 Python 中打印出来时,它会显示出来。但是,我仍然收到TEST FAILED
上面提到的错误消息,只是使用我的新 PYTHONPATH 环境变量。
因此,我尝试将其从 更改/usr/local/python/lib/python2.5
为/usr/local/python/lib/python2.5/site-packages
、导出并easy_install
再次运行相同的命令。这导致了一个全新的结果,起初看起来像是成功(但不是):
Creating /usr/local/python/lib/python2.5/site-packages/site.py
Searching for pil
Reading http://pypi.python.org/simple/pil/
Reading http://www.pythonware.com/products/pil
Reading http://effbot.org/zone/pil-changes-115.htm
Reading http://effbot.org/downloads/#Imaging
Best match: PIL 1.1.7
Downloading http://effbot.org/media/downloads/PIL-1.1.7.tar.gz
Processing PIL-1.1.7.tar.gz
Running PIL-1.1.7/setup.py -q bdist_egg --dist-dir /var/folders/XW/XWpClVq7EpSB37BV3zTo+++++TI/-Tmp-/easy_install-krj9oR/PIL-1.1.7/egg-dist-tmp--Pyauy
--- using frameworks at /System/Library/Frameworks
[snipped: compiler warnings]
--------------------------------------------------------------------
PIL 1.1.7 SETUP SUMMARY
--------------------------------------------------------------------
version 1.1.7
platform darwin 2.5.1 (r251:54863, Sep 1 2010, 22:03:14)
[GCC 4.0.1 (Apple Inc. build 5465)]
--------------------------------------------------------------------
--- TKINTER support available
--- JPEG support available
--- ZLIB (PNG/ZIP) support available
*** FREETYPE2 support not available
*** LITTLECMS support not available
--------------------------------------------------------------------
To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.
To check the build, run the selftest.py script.
zip_safe flag not set; analyzing archive contents...
Image: module references __file__
No eggs found in /var/folders/XW/XWpClVq7EpSB37BV3zTo+++++TI/-Tmp-/easy_install-krj9oR/PIL-1.1.7/egg-dist-tmp--Pyauy (setup script problem?)
同样,这看起来不错,但是当我去运行我的脚本时:
Traceback(最近一次调用最后一次):
文件“checkerboard.py”,第 1 行,在 import Image,ImageDraw ImportError:没有名为 Image 的模块
当我检查现在正在/usr/local/python/
使用的内容find .
时,我得到:
./lib ./lib/python2.5 ./lib/python2.5/site-packages ./lib/python2.5/site-packages/site.py ./lib/python2.5/site-packages/site. pyc
所以......没有任何模块外观(我假设 site.py 和 site.pyc 是元数据或帮助脚本)。安装到哪里去了?
我注意到这一点:
要检查构建,请运行 selftest.py 脚本。
但真的不知道那是什么。
而且我还注意到“没有找到鸡蛋”的消息。这些提示中的任何一个吗?