'which python' and 'echo PYTHONPATH' give different directories, what does this mean?

I'm using Ubuntu 16.04 with python 2.7. I'm trying to run python from a directory other than the one given by

which python

To this end, I put

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

into my bashrc file. Now, which python returns /usr/bin/python and echo PYTHONPATH returns :/home/myname/pybombs/lib/python2.7/dist-packages/.

Shouldn't they return the same directories?

1 Answer

From 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.

The $PYTHONPATH variable just specifies additional locations from which you can import modules. It has nothing to do with the location of the Python interpreter executable that you get as output from which python.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like