finux 发表于 2013-1-15 02:26:38

添加Python Path

1. 查看当前用户的Python Path:
bogon:~ zhu$ pythonPython 2.6.1 (r261:67515, Jul9 2009, 17:39:10) on darwinType "help", "copyright", "credits" or "license" for more information.>>> import sys>>> for s in sys.path:...   print "'%s'" % s... '''/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg''/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages''/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages''/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old''/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload''/Library/Python/2.6/site-packages''/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6''/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC''/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode'>>>  
2. 添加用户的Python Path(Python2.6):
mkdir-p ~/.local/lib/python2.6/site-packages/ 3. 再次查看当前用户的Python Path:
bogon:~ zhu$ python -c 'import sys, pprint; pprint.pprint(sys.path)'['', '/Library/Python/2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.6-universal.egg', '/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages', '/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6/site-packages/wx-2.8-mac-unicode', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python26.zip', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/plat-mac/lib-scriptpackages', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-old', '/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload', '/Users/zhu/.local/lib/python2.6/site-packages', '/Library/Python/2.6/site-packages', '/usr/local/lib/wxPython-unicode-2.8.10.1/lib/python2.6', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/PyObjC', '/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/wx-2.8-mac-unicode'] 呵呵,多了刚刚创建的目录/Users/zhu/.local/lib/python2.6/site-packages
 
这样以后安装/卸载第三方的Python Lib就更方便了,直接将编译好的第三方Lib放到~/.local/lib/python2.6/site-packages/下面就可以了,若是不想要了,就直接删除,呵呵~
 
PS.
OS: Mac OS X 10.6.1
Linux应该也是可以这样来添加用户的Python Path
页: [1]
查看完整版本: 添加Python Path