我使用的是 Ubuntu 16.04 和 Python 2.7。我尝试从除以下目录之外的目录运行 Python:
which python
为此,我把
PYTHONPATH=$PYTHONPATH:/home/myname/pybombs/lib/python2.7/dist-packages/
进入我的 bashrc 文件。现在,which python
返回/usr/bin/python
并echo PYTHONPATH
返回:/home/myname/pybombs/lib/python2.7/dist-packages/
。
它们不应该返回相同的目录吗?
答案1
从man python
:
PYTHONPATH
Augments the default search path for module files. The format
is the same as the shell's $PATH: one or more directory path‐
names separated by colons. Non-existent directories are
silently ignored. The default search path is installation
dependent, but generally begins with ${prefix}/lib/python<ver‐
sion> (see PYTHONHOME above). The default search path is always
appended to $PYTHONPATH. If a script argument is given, the
directory containing the script is inserted in the path in front
of $PYTHONPATH. The search path can be manipulated from within
a Python program as the variable sys.path.
该$PYTHONPATH
变量仅指定可从中导入模块的其他位置。它与您从 输出获得的 Python 解释器可执行文件的位置无关which python
。