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

rzed rzantow at gmail.com
Sat Jun 7 09:55:47 EDT 2008


John Ladasky <ladasky at my-deja.com> wrote in
news:4993bd3d-22aa-4e0d-a593-38c0f5e2d69a at m44g2000hsc.googlegroups.
com: 

> 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!

I can't speak about Linux, but on Windows, you really should move 
your code out of the Python directory tree, I believe. When you 
upgrade, you'll have to be sure to set it up the same way again, 
and remember that your code resides there before you wipe out that 
directory tree, etc. 

Instead, just set up another directory containing your code and add 
that to your PYTHONPATH environment variable string. That will be 
unaffected by the Python version you're running, and will be 
available for multiple versions, if you run more than one.

-- 
rzed



More information about the Python-list mailing list