tags:

views:

39

answers:

3

I have been programming in Python for a while now, and have created some utilities that I use a lot. Whenever I start a new project, I start writing, and as I need these utilities I copy them from where ever I think the latest version of the particular utility is. I have enough projects now that I am losing track of where the latest version is. And, I will upgrade one of these scripts to fix a problem in a specific situation, and then wish it had propagated back to all of the other projects that use that script.

I am thinking the best way to solve this problem is to create a directory in the site-packages directory, and put all of my utility modules in there. And then add this directory to the sys.path directory list.

Is this the best way to solve this problem?

How do modify my installation of Python so that this directory is always added to sys.path, and I don't have to explicitly modify sys.path at the beginning of each module that needs to use these utilities?

I'm using Python 2.5 on Windows XP, and Wing IDE.

+1  A: 

Add your directory to the PYTHONPATH environment variable. For windows, see these directions.

ars
+4  A: 

The site-packages directory within the Python lib directory should always be added to sys.path, so you shouldn't need to modify anything to take care of that. That's actually just what I'd recommend, that you make yourself a Python package within that directory and put your code in there.

Actually, something you might consider is packaging up your utilities using distutils. All that entails is basically creating a setup.py file in the root of the folder tree where you keep your utility code. The distutils documentation that I just linked to describes what should go in setup.py. Then, from within that directory, run

python setup.py install

to install your utility code into the system site-packages directory, creating the necessary folder structure automatically. Or you can use

python setup.py install --user

to install it into a site-packages folder in your own user account.

David Zaslavsky
A: 

If it's not in site-packages then you can add a file with the extension .pth to your site-packages directory.

The file should have one path per line, that you want included in sys.path

Joe Koberg