Change import order with *.pth files

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Mon Oct 3 04:14:20 EDT 2011


En Sun, 02 Oct 2011 18:29:24 -0300, Andrea Gavana  
<andrea.gavana at gmail.com> escribió:

> Let's say I am using a package called "blah", and this package is already
> installed on site-packages (and I need it to be there) with a name
> "blah-1.2-win". In the site-packages folder, there is a pth file called
> "blah.pth" which contains this line:
>
> blah-1.2-win
>
> To redirect Python to the correct folder when I type "import blah".  
> Anyway,
> now I am developing another version of this package and it's called
> "blah-2.0-win", and it sits on my computer into a different folder (not  
> on
> site-packages, on an entire different drive in reality). How can I tell
> Python *not* to use the version inside site-packages but to use the other
> one in my development folder (without touching the pth file in
> site-packages, of course)?

 From Python 2.6 on, there is a per user site-packages directory, which is  
searched before the global one. See:

http://docs.python.org/whatsnew/2.6.html#pep-370-per-user-site-packages-directory

You could put your developing version on that directory.

In Python 2.5 and earlier, if you have to PREPEND a directory to sys.path,  
you may set the PYTHONPATH environment variable, or edit the site.py  
standard module. This may be fine in your development environment, but I  
would never do that in production.

-- 
Gabriel Genellina




More information about the Python-list mailing list