“which python”和“echo PYTHONPATH”给出不同的目录,这是什么意思?

“which python”和“echo PYTHONPATH”给出不同的目录,这是什么意思?

我使用的是 Ubuntu 16.04 和 Python 2.7。我尝试从除以下目录之外的目录运行 Python:

which python

为此,我把

PYTHONPATH=$PYTHONPATH:/home/myname/pybombs/lib/python2.7/dist-packages/

进入我的 bashrc 文件。现在,which python返回/usr/bin/pythonecho 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

相关内容