Я использую 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/.
Не должны ли они возвращать одни и те же каталоги?
Из 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.
Из 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.
Из 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.