python读取类库的顺序是,当前目录,pythonpath,path和安装目录。可以动态的设置pythonpath如下:
- Python 2.6.3 (r263rc1:75186, Oct 2 2009, 20:40:30) [MSC v.1500 32 bit (Intel)]
- on win32
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import sys
- >>> sys.path
- ['', 'C:\\Python26', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs',
- 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk'
- , 'C:\\Python26\\lib\\site-packages']
- >>> sys.path.append('c:\\path')
- >>> sys.path
- ['', 'C:\\Python26', 'C:\\Windows\\system32\\python26.zip', 'C:\\Python26\\DLLs',
- 'C:\\Python26\\lib', 'C:\\Python26\\lib\\plat-win', 'C:\\Python26\\lib\\lib-tk'
- , 'C:\\Python26\\lib\\site-packages', 'c:\\path']
- >>>
还有就是修改环境变量。增加一个PYTHONPATH
windows比较讨厌的是有空格问题。
在系统变量里面增加一个变量PYTHONPATH
值是:
- C:\\Program Files (x86)\\Google\\google_appengine;C:\\Program Files (x86)\\Google\\google_appengine\\lib\\antlr3;C:\\Program Files (x86)\\Google\\google_appengine\\lib\\django;C:\\Program Files (x86)\\Google\\google_appengine\\lib\\webob;C:\\Program Files (x86)\\Google\\google_appengine\\lib\\yaml\\lib;C:\\Program Files (x86)\\Google\\google_appengine;
只是gae执行起来还是有点问题,保存modle的时候,说没有app id。咳。
———–
python 2.6 开始,好像支持在site-packages目录下建xxx.pth的文件,把要include的lib path写进去即可。这个方便,易于维护。不错
更多可以看这个 http://docs.python.org/library/site.html
Popularity: 4%