在尝试编写今天使用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尚未存在,所以我创建它,然后再试一次,得到这个:
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:
06001
and your PYTHONPATH environment
variable currently contains:
06002
好吧,公平 – 我没有做任何事情来设定路径.所以我给〜/ .bash_profile添加了一个快速行:
PYTHONPATH=”$PYTHONPATH:/usr/local/python/lib/python2.5″
并采购它,然后再试一次.
相同的错误消息.
考虑到PYTHONPATH显然是固定的,这有点好奇;我可以回显$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将此位置识别为包含路径?
UPDATE
正如Sven Marnach所说,我忽略了出口PYTHONPATH.我已经纠正了这个问题,现在看到它出现在我从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.
但是真的不知道那是什么.
我还注意到“没有发现鸡蛋”的消息.这些提示中的任何一个?