在尝试编写一个使用PIL的Python脚本的过程中,我发现我的本地机器上似乎没有它(OS X 10.5.8,默认的2.5python安装)。
所以我跑:easy_install --prefix=/usr/local/python/ pil
它抱怨/usr/local/python/lib/python2.5/site-packages还不存在,所以我创建了它,然后再试一次,得到:TEST FAILED:
/usr/local/python//lib/python2.5/site-packages
does NOT support .pth files error: bad
install directory or PYTHONPATH
You are attempting to install a
package to a directory that is not on
PYTHONPATH and which Python does not
read ".pth" files from. The
installation directory you specified
(via --install-dir, --prefix, or the
distutils default setting) was:/usr/local/python//lib/python2.5/site-packages
and your PYTHONPATH environment
variable currently contains:''
好吧,很公平——我没有做任何事情来确定道路。所以我在~/.bash_配置文件中添加了一个快速行:PYTHONPATH="$PYTHONPATH:/usr/local/python/lib/python2.5"
然后source再试一次。
相同的错误消息。
这有点奇怪,因为PYTHONPATH已经设置好了;我可以echo $PYTHONPATH然后返回:/usr/local/python/lib/python2.5。我决定从内部查看include路径的外观: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将此位置识别为包含路径?
更新
正如kldm建议的那样,我忽略了Python的出口。我已经纠正了这个问题,现在看到它在我从Python中打印出sys.path时出现。但是,我仍然得到了上面提到的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 (most recent call last):
File "checkerboard.py", line 1, in
import Image, ImageDraw ImportError: No module named Image
当我使用find .检查/usr/local/python/下面的内容时,我得到:./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是元数据或帮助脚本)。安装到哪里去了?
我注意到:To check the build, run the
selftest.py script.
但不知道那是什么。
我也注意到了“找不到鸡蛋”的信息。这是暗示吗?