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.
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.
Use sys. path for that. By simple experiment, I found Vanuan's answer below (printing sys. path) just prints PYTHONPATH.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With