Python 和 tcsh 的 sys.path 中没有路径
我对 tcsh 没有太多经验,但我有兴趣学习。 我在让 Python 查看 PYTHONPATH
时遇到问题。 我可以回显 $PYTHONPATH
,它是正确的,但是当我启动 Python 时,我的路径不会显示在 sys.path
中。 有任何想法吗?
编辑:
[dmcdonal@tg-steele ~]$ echo $PYTHONPATH
/home/ba01/u116/dmcdonal/PyCogent-v1.1
>>> from sys import path
>>> from os import environ
>>> path
['', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/FiPy-2.0-py2.5.egg', '/apps/steele/Python-2.5.2', '/apps/steele/Python-2.5.2/lib/python25.zip', '/apps/steele/Python-2.5.2/lib/python2.5', '/apps/steele/Python-2.5.2/lib/python2.5/plat-linux2', '/apps/steele/Python-2.5.2/lib/python2.5/lib-tk', '/apps/steele/Python-2.5.2/lib/python2.5/lib-dynload', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/Numeric']
>>> environ['PYTHONPATH']
'/apps/steele/Python-2.5.2'
I don't have much experience with tcsh, but I am interested in learning. I've been having issues getting Python to see PYTHONPATH
. I can echo $PYTHONPATH
, and it is correct, but when I start up Python, my paths do not show up in sys.path
. Any ideas?
EDIT:
[dmcdonal@tg-steele ~]$ echo $PYTHONPATH
/home/ba01/u116/dmcdonal/PyCogent-v1.1
>>> from sys import path
>>> from os import environ
>>> path
['', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/setuptools-0.6c8-py2.5.egg', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/FiPy-2.0-py2.5.egg', '/apps/steele/Python-2.5.2', '/apps/steele/Python-2.5.2/lib/python25.zip', '/apps/steele/Python-2.5.2/lib/python2.5', '/apps/steele/Python-2.5.2/lib/python2.5/plat-linux2', '/apps/steele/Python-2.5.2/lib/python2.5/lib-tk', '/apps/steele/Python-2.5.2/lib/python2.5/lib-dynload', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages', '/apps/steele/Python-2.5.2/lib/python2.5/site-packages/Numeric']
>>> environ['PYTHONPATH']
'/apps/steele/Python-2.5.2'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你是如何设置 PYTHONPATH 的? 您可能会混淆 tcsh 的 set 与 setenv。 使用“set”设置 tcsh 调用的 shell 变量,并使用“setenv”设置环境变量。 因此,您需要使用 setenv 才能让 Python 看到它。 例如:
tcsh 文档的变量部分。
How are you setting PYTHONPATH? You might be confusing tcsh's set vs. setenv. Use "set" to set what tcsh calls shell variables and use "setenv" to set environment variables. So, you need to use setenv in order for Python to see it. For example:
There is some more information available in the variables section of the tcsh documentation.
确保您没有使用
-E
选项启动 python(即:忽略环境变量)。 如果您通过 shell 脚本或其他应用程序启动 python,只需仔细检查它没有添加任何内容。由于 sys.path 列表很长,因此很难错过您的路径。 PYTHONPATH 内容通常会添加到列表的中间位置(在所有库路径之后)。 有没有可能你的路径在那里,只是埋在中间?
Make sure that you're not starting python with the
-E
option (which is: ignore environment variables). If you start python via a shell script or some other app, just double check it doesn't add anything.Since the list of sys.path is long, it can be hard to miss your paths. PYTHONPATH stuff normally gets added to about the middle of the list, after all the library paths. Any chance your paths are there, just buried in the middle?
检查:
如果是,并且您可以确认您的路径不在 sys.path 中,则您发现了一个错误。
如果它不在 os.environ 中,则您的环境不会传递到 Python(可能是另一个错误)。
当然,向我们展示实际的代码/导出,有人会很快告诉您。
Check:
If it is, and you can confirm that your paths are not in sys.path, you have found a bug.
If it is not in os.environ, your environment is not passing through to Python (probably another bug).
Of course, show us the actual code/exports, and someone will tell you pretty quickly.
即使我在使用 Python
2.5.1
时在.cshrc
中正确设置环境PYTHONPATH
,当我切换到 Python 时,我也遇到同样的问题2.6.2
,工作正常。 看起来这是一个 python bug。I also have the same issue even I set environment
PYTHONPATH
correctly in.cshrc
when I used Python2.5.1
, when I switch the to Python2.6.2
, It works fine. Looks like it is a python bug.