Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What exactly should be set in PYTHONPATH?

Tags:

python

I'm going through and writing a setup doc for other developers at work for a python project and I've been reading up on the PYTHONPATH environment variable. I'm looking at my current development system and think I have a few things set wrong that is causing my IDE (IntelliJ) to behave incorrectly when looking up the python libraries.

I've looked at the documentation here and here and I'm still unsure of what should actually be in the PYTHONPATH environment variable.

I have PYTHONHOME pointed to `C:\Python27'.

My current PYTHONPATH is set to PYTHONHOME. Should I also add the directories from sys.path?

UPDATE:

Based on the below information, PYTHONPATH does not need to be set unless there are non-standard libraries that you want python to be able to find by default. For instance, when I install wxPython from the installer it will add its libraries to PYTHONPATH. I do set PYTHONHOME to the root of the python installation so that I can add it to my system PATH environment variable so that I can run python from any where.

like image 322
Casey Avatar asked Oct 21 '11 14:10

Casey


People also ask

Why might you have to set your Pythonpath environment variable?

So, the only reason to use PYTHONPATH variables is to maintain directories of custom Python libraries that are not installed in the site packages directory (the global default location). In simple terms, it is used by user-defined modules to set the path so that they can be directly imported into a Python program.

How do I know if Pythonpath is set?

Use sys. path for that. By simple experiment, I found Vanuan's answer below (printing sys. path) just prints PYTHONPATH.

Where does Pythonpath get set?

PYTHONPATH is an environment variable those content is added to the sys. path where Python looks for modules. You can set it to whatever you like.


1 Answers

You don't have to set either of them. PYTHONPATH can be set to point to additional directories with private libraries in them. If PYTHONHOME is not set, Python defaults to using the directory where python.exe was found, so that dir should be in PATH.

like image 124
Mark Tolonen Avatar answered Oct 01 '22 06:10

Mark Tolonen