ImportError: No module named trac

Apologies for the more gentile readers for this niche technical post, but I’m hoping to solve my technical brothers and sisters some frustrations with Trac, the excellent open source issue tracking system (we’ve been using it for more than 2 years to manage our work with Yankee Publishing, and it’s been truly transformational).

If you’re upgrading from Trac 0.11 to Trac 0.12 and you’re using Trac with Apache and mod_python you might find that after you upgrade you either get a “500 Internal Server Error” form Apache when you visit Trac or, if you have mod_python debugging on (or if you look in your Apache error log), an error message ImportError: No module named trac.

And yet you think that Trac actually is there: you can use trac-admin from the command line, and if you look where you think Trac should be (say, perhaps, in /usr/lib/python2.4/site-packages), you find that it is indeed there.

What’s going on?

It seems that Trac 0.12, at least when I installed it, installs itself as a “zipped egg.” I realized this was true when, after I did:

easy_install Trac-0.12b1.zip

I ended up with a file (not a directory) in /usr/lib/python2.4/site-packages. My earlier versions of Trac were directories, not files. This, and this helpful post that says, in part:

mod_python 3.x is still unable to import modules from .zipped .egg-files. Command-line python (even older version 2.4 which is included into RHEL5/CentOS5) imports modules from zipped eggs without any problem, but not mod_python for the same version because it overrides the standard importer in its own special way.

So, in other words, Trac is there, it’s just that mod_python can’t see it because it’s zipped. Once I knew this, the solution was easy:

easy_install --always-unzip Trac-0.12b1.zip

Installing this way ensures that the resulting egg isn’t zipped, and once I did this Trac 0.12 ran without issue.

Comments

Chuck's picture
I predict this will post will generate some very high traffic numbers over time.
Peter Rukavina's picture

Traffic numbers are low, but, as you can see from comments that follow, the post has been of some surgical help to those in need. Which was my reason for writing.

Dani's picture

Thanks !!! it really helped me.
I just unzipped the egg and it solved the problem !

w00ten's picture

THANK YOU!!!!!! After 2 and a half hours of dicking around with python and YUM being retarded I had this happen and this is the ONLY website that is even remotely on an understandable level or is even in a readable layout. Took me 30 seconds after reading this. Apparently Trac dev's screwed up hard if they forgot to make sure the egg is unzipped.

ra's picture

Posted some links to this page on trac website, in tickets concerning this problem.
Oh, and it helped me too, thanks.

schweini's picture

I installed the mastertickets plugin, and foolishly ran the included 'setup.py', and was wondering why it decided to update my trac installation to 0.12 without me asking it to. That dreaded 500 Internal Server Error appeared, and this post here is the ONLY place i found the solutino for this. Thanks a bunch!

M.

Brennan's picture

Thank you so much for posting this. To reiterate what an earlier commenter has said, it seems like you're the only person on the web who has solved this problem, and it was such a quick solution.

PablooDemon's picture

Thank You!

You saved my life. I was fighting with Trac for the last 3 days. It is finally working.

Thank You!

Pascal's picture

OH MY GOD! Thank you!
This error was driving me insane!

Jack Chiu's picture
Thank you very much~
Redux's picture
mate - Thanks very much!
Spike's picture
This was helpful, but it didn’t work until I removed the Trac-0.12.1.py2.4.egg from /usr/lib/python2.4/site-packages then ran the easy_install —always-unzip —upgrade Trac==0.12.1 again.
janton's picture

Yep Many Many thx!

Don't forget to restart apache! (was needed in my case)
CentOS:
service httpd restart

  

Post new comment

You can comment anonymously if you must, but I would prefer it if you used your real name.
The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
Optional. If you enter the address of a website here, your name will be publicly linked to the site.
  • Adds typographic refinements.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.