Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set PYTHONPATH to multiple folders

Tags:

In ~/.bash_profile file (OS X) I've set PYTHONPATH to point to two folders:

export PYTHONPATH=/Applications/python/common:$PYTHONPATH export PYTHONPATH=/Applications/sitecustomize:$PYTHONPATH 

Even while sitecustomize folder is set on a second line (after /common) the first path is ignored and I am not able to import any module from the path defined in a first line. What needs to be revised in above syntax to make both folders PYTHONPATHish to Python?

like image 935
alphanumeric Avatar asked Sep 25 '16 01:09

alphanumeric


People also ask

Can I have multiple Pythonpath?

Background. Setting the PYTHONPATH environment variable is an easy way to make Python modules available for import from any directory. This environment variable can list one or more directory paths which contain your own modules. On Windows, multiple paths are separated by semicolons.

What is the purpose of Pythonpath environment variable?

PYTHONPATH is an environment variable which you can set to add additional directories where python will look for modules and packages. For most installations, you should not set these variables since they are not needed for Python to run. Python knows where to find its standard library.


1 Answers

Append your paths so there is only one PYTHONPATH.

PYTHONPATH="/Applications/python/common:/Applications/sitecustomize:$PYTHONPATH" export PYTHONPATH 

Then source ~/.bash_profile

OR import them into your Python script (this would only work for the script added to):

import sys sys.path.append("/Applications/python/common") sys.path.append("/Applications/sitecustomize") 
like image 62
Chris Townsend Avatar answered Oct 14 '22 21:10

Chris Townsend