此 Python 脚本显示其路径包含/home/web/public_html/module/disc/static/python/lib/python2.4/site-packages
:
$ python serverTest.py
This is my sys.path:
['/home/web/public_html/module/disc/static/python/lib/python2.4/site-packages',
'/home/web/public_html/module/disc/static/python',
'/usr/lib64/python24.zip',
'/usr/lib64/python2.4',
'/usr/lib64/python2.4/plat-linux2',
'/usr/lib64/python2.4/lib-tk',
'/usr/lib64/python2.4/lib-dynload',
'/usr/lib64/python2.4/site-packages',
'/usr/lib64/python2.4/site-packages/Numeric',
'/usr/lib64/python2.4/site-packages/gtk-2.0',
'/usr/lib/python2.4/site-packages']
Traceback (most recent call last):
File "serverTest.py", line 27, in ?
import simplejson as json
ImportError: No module named simplejson
$ export PYTHONPATH=$PYTHONPATH:/home/web/public_html/module/disc/static/python/lib/python2.4/site-packages
$ python serverTest.py
Hello, world!
可以看出,虽然目录在sys.path
脚本里面,但是找不到simplejson
安装在那里的。PYTHONPATH
但是,当我在 Bash 中添加相同的路径时,simplejson
就会找到。如何修复它以便在simplejson
不设置 Bash 变量的情况下可用?
编辑:
>>> sys.path
['/home/webtov/public_html/module/discoapi/static/python',
'',
'/home/webtov/public_html/module/discoapi/static/python/lib/python2.4/site-packages',
'/home/webtov/local/',
'/home/webtov/local/lib/python2.4/site-packages/',
'/usr/lib64/python24.zip',
'/usr/lib64/python2.4/',
'/usr/lib64/python2.4/plat-linux2',
'/usr/lib64/python2.4/lib-tk',
'/usr/lib64/python2.4/lib-dynload']
>>> json.__path__
['/home/webtov/public_html/module/discoapi/static/python/lib/python2.4/site-packages',
'/home/webtov/public_html/module/discoapi/static/python',
'',
'/home/webtov/public_html/module/discoapi/static/python/lib/python2.4/site-packages',
'/home/webtov/local/',
'/home/webtov/local/lib/python2.4/site-packages/',
'/usr/lib64/python24.zip',
'/usr/lib64/python2.4/',
'/usr/lib64/python2.4/plat-linux2',
'/usr/lib64/python2.4/lib-tk',
'/usr/lib64/python2.4/lib-dynload']