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

Roy Smith roy at panix.com
Wed Nov 16 20:57:42 EST 2011


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',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib/python2.6/lib-old',
 '/usr/lib/python2.6/lib-dynload',
 '/usr/lib/python2.6/dist-packages',
 '/usr/lib/python2.6/dist-packages/PIL',
 '/usr/lib/python2.6/dist-packages/gst-0.10',
 '/usr/lib/pymodules/python2.6',
 '/usr/lib/python2.6/dist-packages/gtk-2.0',
 '/usr/lib/pymodules/python2.6/gtk-2.0',
 '/usr/local/lib/python2.6/dist-packages']

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.



More information about the Python-list mailing list