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


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?


From man python:

          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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.