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.
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.pyfile 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 insetup.py. Then, from within that directory, runto install your utility code into the system
site-packagesdirectory, creating the necessary folder structure automatically. Or you can useto install it into a
site-packagesfolder in your own user account.