«какие 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/python и echo PYTHONPATH возвращает :/home/myname/pybombs/lib/python2.7/dist-packages/.

Не должны ли они возвращать одни и те же каталоги?

1
задан 1 August 2017 в 16:25

3 ответа

Из 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.

0
ответ дан 22 May 2018 в 19:56

Из 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.

0
ответ дан 18 July 2018 в 09:16

Из 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.

0
ответ дан 24 July 2018 в 19:17

Другие вопросы по тегам:

Похожие вопросы: