python库路径_如何设置本地python库目录/ PYTHONPATH?
在嘗試編寫今天使用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.
但是真的不知道那是什么.
我還注意到“沒有發現雞蛋”的消息.這些提示中的任何一個?
總結
以上是生活随笔為你收集整理的python库路径_如何设置本地python库目录/ PYTHONPATH?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java字符流实际上也是字节,[Java
- 下一篇: ubuntu安装python编译器_Ub