PYTHONPATH 变量空白

标签 python sys.path

根据documentation , sys.path 在 Python 解释器 session 启动时从 PYTHONPATH 初始化。但是,就我而言,PYTHONPATH 变量为空。当我在终端中执行此操作时:

echo $PYTHONPATH

它返回空白。另一方面,当我启动Python REPL并检查sys.path:

import sys
print (sys.path)

我得到了一长串路径。这些是从哪里加载的?我错过了什么?

最佳答案

Check the documentation again :

上面写着

[sys.path is initialized] from the environment variable PYTHONPATH, plus an installation-dependent default.

此外,

the first item of this list, path[0], is the directory containing the script that was used to invoke the Python interpreter [… or] the empty string

这就是为什么你的不为空。

关于PYTHONPATH 变量空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48599467/

相关文章:

python - 更改 Pyscripter 中的主题?

python - 管理多个开发人员的 sys.path

python-2.7 - python2.7正常调用和subprocess调用时sys.path的区别

Python 在 IDLE 中播放声音,但在 Thonny 中给出 "no module called gi"错误; Ubuntu 终端中的混合结果

python - 在 python 中导入 beautifulsoup

python - 如何在 Python 中跳过匹配模式的行?

python - 意外错误 : replace() takes 2 positional arguments but 3 were given

python - 如何使用 Python 从 pdf 中提取文本?

python - Python 迭代哪种方法更快?

python - 使用 Python .pth 文件假设无权访问 site-packages 目录