35

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?

baranskistad
  • 2,176
  • 1
  • 21
  • 42
alphanumeric
  • 17,967
  • 64
  • 244
  • 392

1 Answers1

52

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")
Chris Townsend
  • 3,042
  • 27
  • 31
  • 3
    If on the Windows platform, use a ; character to separate modules in this environment variable instead of a : character for the Linux platform. – JustBeingHelpful Apr 11 '23 at 23:17