I am trying to use third party packages in Python. To import all the modules I need to update PYTHONPATH. I read several blogs on it but still I have following questions unanswered.

  1. Is sys.path & PYTHONPATH are same things ? (probably not)

  2. How to see current value of PYTHONPATH (which is something called environmental variable) ?

  3. How to update PYTHONPATH permenently ?

I know I can do sys.path.append('/<PATH>'), but that updates sys.path until you do not exit the Python interpreter.


(I know this but I do not know what is current $PYTHONPATH)

How do I update PYTHONPATH permanently ?

  1. I'm not into phython, but it seems that the sys.path variable is just an accessor to the system-wide PYTHONPATH variable. If you modify it, the PYTHONPATH variable won't be changed, only the sys.path python variable.
  2. Type into your command prompt: echo $PYTHONPATH If it shows nothing, PYTHONPATH isn't set at all.
  3. Add that export ... line at the end of the .bashrc file of the concerning user's home directory and restart your shell.
  1. sys.path contains paths from PYTHONPATH environment variable plus the folder the script was started from. See more info here
  2. echo $PYTHONPATH in a terminal or import os; print os.environ['PYTHONPATH'] (from Python, will work if such a variable was defined)
  3. To set an environment variable for all applications, read this. Add this export PYTHONPATH=$PYTHONPATH:/path/to/some/package to ~/.pam_environment file.

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.