Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
根据文档, sys.path 在 python 会话启动时从 PYTHONPATH 初始化。但是,就我而言, PYTHONPATH 变量为空。当我在终端中执行此操作时:
echo $PYTHONPATH
它返回空白。另一方面,当我启动 python 并检查 sys.path 时:
import sys print (sys.path)
我得到了一长串路径。那些是从哪里加载的?我错过了什么?
再次检查文档:
它说
[sys.path被初始化]来自环境变量PYTHONPATH,加上依赖于安装的默认值。
sys.path
PYTHONPATH
此外,
该列表的第一项path[0]是包含用于调用 Python 解释器的脚本的目录 [... 或] 空字符串
path[0]
这就是为什么你的不是空的。