Workaround for “ImportError: cannot import name compat” issue in Trac 0.11.x

I had used Trac 0.10.4 for awhile before upgrading to 0.11. First time around I had no problems, but on a new server, a fresh install of 0.11.1 was giving me this error when I visit certain pages:

[Sun Aug 10 19:41:57 2008] [error] [client 69.204.200.139] PythonHandler trac.web.modpython_frontend: Traceback (most recent call last):, referer: http://issues.biodegradablegeek.com/congen9
[Sun Aug 10 19:41:57 2008] [error] [client 69.204.200.139] PythonHandler trac.web.modpython_frontend:   File "/usr/lib/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatchn    result = object(req), referer: http://issues.biodegradablegeek.com/congen9
[Sun Aug 10 19:41:57 2008] [error] [client 69.204.200.139] PythonHandler trac.web.modpython_frontend:   File "/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/web/modpython_frontend.py", line 148, in handlern    from trac.web.main import dispatch_request, referer: http://issues.biodegradablegeek.com/congen9
[Sun Aug 10 19:41:57 2008] [error] [client 69.204.200.139] PythonHandler trac.web.modpython_frontend:   File "/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/web/main.py", line 47, in ?n    from trac.web.chrome import Chrome, referer: http://issues.biodegradablegeek.com/congen9
[Sun Aug 10 19:41:57 2008] [error] [client 69.204.200.139] PythonHandler trac.web.modpython_frontend:   File "/usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/web/chrome.py", line 40, in ?n    from trac.util import compat, get_reporter_id, presentation, get_pkginfo, \, referer: http://issues.biodegradablegeek.com/congen9

After further investigation, it appears I had two compat.py files on my system:

mercury@tryptamine: /usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac $ find . -name compat*
./util/compat.py
./util/compat.pyc
./tests/functional/compat.py
./tests/functional/compat.pyc

Renaming compat.py to testcompat.py in trac/tests/functional/ fixes the problem perfectly:

cd /usr/lib/python2.4/site-packages/Trac-0.11.1-py2.4.egg/trac/tests/functional/
sudo mv compat.py testcompac.py
sudo mv compat.pyc testcompac.pyc

The compat.pyc file may also be deleted.

That’s it. No restarting Trac/httpd.

I don’t take credit for this. Thanks goes to Jashugan (trac-users)!

5 thoughts on “Workaround for “ImportError: cannot import name compat” issue in Trac 0.11.x”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>