Python 和 tcsh 的 sys.path 中没有路径

发布于 2024-07-14 12:35:55 字数 1014 浏览 8 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

燃情 2024-07-21 12:35:55

你是如何设置 PYTHONPATH 的? 您可能会混淆 tcsh 的 set 与 setenv。 使用“set”设置 tcsh 调用的 shell 变量,并使用“setenv”设置环境变量。 因此,您需要使用 setenv 才能让 Python 看到它。 例如:

$ set FOO='bar'
$ echo $FOO
bar
$ python -c 'import os; print os.getenv("FOO")'
None

$ setenv BAR 'wiz'
$ echo $BAR
wiz
$ python -c 'import os; print os.getenv("BAR")'
wiz

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:

$ set FOO='bar'
$ echo $FOO
bar
$ python -c 'import os; print os.getenv("FOO")'
None

$ setenv BAR 'wiz'
$ echo $BAR
wiz
$ python -c 'import os; print os.getenv("BAR")'
wiz

There is some more information available in the variables section of the tcsh documentation.

淡看悲欢离合 2024-07-21 12:35:55

确保您没有使用 -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?

你是年少的欢喜 2024-07-21 12:35:55

检查:

  1. PYTHONPATH 位于 os.environ 中,
  2. 并设置为冒号分隔的路径列表的正确值。

如果是,并且您可以确认您的路径不在 sys.path 中,则您发现了一个错误。

如果它不在 os.environ 中,则您的环境不会传递到 Python(可能是另一个错误)。

当然,向我们展示实际的代码/导出,有人会很快告诉您。

Check:

  1. PYTHONPATH is in os.environ,
  2. and set to the correct value of a colon separated list of paths.

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.

甜中书 2024-07-21 12:35:55

即使我在使用 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 Python 2.5.1, when I switch the to Python 2.6.2, It works fine. Looks like it is a python bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文