根据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 variablePYTHONPATH
, 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/