Sat 10 Jul 2010
While trying to run our tests in a clean virtualenv (–no-site-packages), psycopg2 (tried both 2.0.13 and 2.0.14) can not be imported with a error traceback like the following:
File "....py", line .., in import psycopg2 File "build/bdist.linux-i686/egg/psycopg2/__init__.py", line 69, in File "build/bdist.linux-i686/egg/psycopg2/_psycopg.py", line 7, in File "build/bdist.linux-i686/egg/psycopg2/_psycopg.py", line 6, in __bootstrap__ ImportError: can't import mx.DateTime module
However, search python source files in the install psycopg2 package does not yeild any hits on mx, so my conclude was that it’s being imported in the psycopg2 c library.
It becomes clear after I took a look at the setup.py in the source tarball of psycopg2: while building the package, the setup.py will check whether it can find mx header files under the python include dir. If it can, it would just compile in the above import line into its c library. I don’t see any way it can be disabled given you have egenix-mx-base header files installed (even if you don’t have mx python module available, it will still compile in mx.DateTime support)
This would only happen if you have the egenix-mx-base header files install in the global python installation.
One workaround I came up with is to copy over the mx dir under site-packages from the global python installation into the virtualenv environment I am using to do test. Alternatively, don’t install the header files for egenix-mx-base (although in gentoo, that means you have to manually remove the header files). For now, I settled on the former workaround.