0

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.

export `PYTHONPATH=$PYTHONPATH:/<PATH>

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

How do I update PYTHONPATH permanently ?

2 Answers 2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .