Import, site packages, my modules, Windows vs. Linux

John Ladasky ladasky at my-deja.com
Wed Jun 4 02:57:07 CEST 2008


Hi folks,

Running Python 2.5 on both a Windows XP laptop, and an Ubuntu Linux
7.04 desktop.

I've gotten tired of maintaining multiple copies of my personal
modules that I use over and over.  I have copies of these files in the
same directory as the main program I happen to be working on at the
time.  I've also downloaded FANN, and want to use its Python
bindings.  FANN does not seem to build automatically, like wxWidgets
did.

These two issues have led me to examine exactly how the import
statement works, how the PYTHONPATH environment variable is
constructed, and how to change it.

On Windows I found a solution that works, but which may be a kludge.
In the Python "site-packages" folder, I added a sub-folder called "my-
packages".  Then I created a text file, "my-packages.pth", containing
the single line, "my-packages."  Finally, I moved my common personal
modules into the my-packages folder and deleted all of my clumsy
duplicates.  Import statements now work for all of my files on the
Windows box, great!

I then tried to use this same strategy in Linux, and saw that I don't
automatically have the privileges needed to alter the site-packages
folder.  On my Windows box, my default account has Administrator
privileges.  On Linux I can, of course, use sudo to modify the site-
packages folder.  But the fact that I would have to use sudo has me
asking -- is there something inappropriate, or unsafe in my approach?

I want to know what is the *recommended* way to integrate my own
personal modules with Python.  Thanks!



More information about the Python-list mailing list