Change import order with *.pth files

Andrea Crotti andrea.crotti.0 at gmail.com
Sun Oct 2 17:57:23 EDT 2011


On 10/02/2011 10:29 PM, Andrea Gavana wrote:
> Hi All,
>
>     my apologies if this is a dumb question, but I couldn't find a 
> solution  - possibly because I am not sure how to state my problem in 
> a short sentence.
>
> 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)?
>
> I have tried fiddling with sys.path and to create a local (in my 
> development folder) pth file, to no avail. I hope I have been able to 
> explain my problem clearly... This is on Windows, Python 2.5 to 2.7.
>
> Thank you in advance for your suggestions.
>
> Andrea.

Well messing up with the pth file is not a very good idea in general, 
since it's thought to be manipulated by distutils, not by hand.

The best way to solve your problem is to use virtualenv or something 
similar, check it out...




More information about the Python-list mailing list