adding a directory to sys.path

John Guenther johnguenther at
Mon Nov 23 18:02:36 CET 2009

This is Mac related. I am running snow leopard. I am using Python 2.6.3.

I had a lot of difficulty figuring out how to add a directory to sys.path that would be there every time I launched Idle. I have a directory called PythonPrograms in my Documents folder. When I installed Python it had '/Users/johnguenther/Documents' as sys.path[0]. I tried setting PYTHONPATH and this worked for running Python  from the bash shell but only until I exited the shell. PYTHONPATH had to be reset each time I restarted the shell. And it had no effect on sys.path when I ran Idle.

I tried putting files with names ending with .pth in various directories all of which were already in sys.path. In this file I would put the path name of the directory, i.e., '/Users/johnguenter/Documents/PythonPrograms'. This had absolutely no effect.

I searched the web for help and found nothing that worked. 

Finally I looked at a file that had been installed when I installed wxPython. I modified that file and now the directory I want is always part of sys.path when I start idle. 

Since I had so much trouble finding an answer to the question "How do I permanently change sys.path?", I thought I might post this message.

I created a file called myconfig.pth

In this file I included one line:

import site; site.addsitedir('/Users/johnguenther/Documents/PythonPrograms')

I placed the file in /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages. 

More information about the Python-list mailing list