How to insert my own module in front of site eggs?

Marc Christiansen usenet at solar-empire.de
Thu Nov 17 04:48:17 EST 2011


Roy Smith <roy at panix.com> wrote:
> I'm trying to use a custom version of mongoengine.  I cloned the git 
> repo and put the directory on my PYTHONPATH, but python is still 
> importing the system's installed version.  Looking at sys.path, it's 
> obvious why:
> 
> $ echo $PYTHONPATH 
> /home/roy/songza:/home/roy/lib/mongoengine
> 
>>>> pprint.pprint(sys.path)
> ['',
> '/usr/local/lib/python2.6/dist-packages/selenium-2.0a5-py2.6.egg',
> '/usr/local/lib/python2.6/dist-packages/unittest2-0.5.1-py2.6.egg',
> 
> '/usr/local/lib/python2.6/dist-packages/pymongo-1.9-py2.6-linux-x86_64.eg
> g',
> '/usr/local/lib/python2.6/dist-packages/virtualenv-1.5.2-py2.6.egg',
> '/usr/local/lib/python2.6/dist-packages/mongoengine-0.5.2-py2.6.egg',
> '/home/roy/songza',
> '/home/roy/lib/mongoengine',
[...]

> The system eggs come before my path.  I found 
> http://mail.python.org/pipermail/distutils-sig/2006-July/006520.html in 
> the archives; it explains that eggs come before PYTHONPATH, but doesn't 
> explain how to get around this problem.  I emphatically agree with 
> Michael Bayer who said:
> 
>> I cant think of a  possible scenario where a path would explicitly
>> exist in PYTHONPATH,  non-egg or egg, where the user would still like the
>> system-wide installation to take precedence
> 
> So, is there any way to get my local copy of mongoengine loaded instead 
> of the system egg?  I could probably import sys, and do an egg-ectomy on 
> sys.path before importing mongoengine, but that's too gross to 
> contemplate.

The only way I found is to edit the easy_install.pth file and comment
the two lines starting with "import sys". You'll have to do that every
time you install/upgrade an egg via easy_install (and maybe setuptools).
In your case the right file should be
/usr/local/lib/python2.6/dist-packages/easy_install.pth

BTW: You could try pip (http://www.pip-installer.org/) instead of
easy_install, it doesn't mess with sys.path.

Ciao
Marc



More information about the Python-list mailing list