ImportError: No module named trac

Peter Rukavina

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

Submitted by w00ten on

Permalink

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.

Submitted by ra on

Permalink

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

Submitted by schweini on

Permalink

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.

Submitted by Brennan on

Permalink

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.

Submitted by PablooDemon on

Permalink

Thank You!

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

Thank You!

Submitted by Peter Rukavina on

Permalink

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.

Submitted by Spike on

Permalink

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.

Submitted by janton on

Permalink

Yep Many Many thx!


Don&#39t forget to restart apache! (was needed in my case)

CentOS:

service httpd restart



 

Submitted by FragFrog on

Permalink

Thank you! A thousand times, thank you! I cannot believe this actually worked, but it did =D

Note: I had already installed the .egg’s the normal way, deleting them and then reinstalling them (with easy_install) did the trick.

Submitted by Jorge on

Permalink

I had a similar problem and after i tried everything i found that the problem was in the permissions of the /usr/lib/python2.4/site-packages directory (i installed trac as root), i changed the owner of the directory and all subdirectories and files and it worked like a charm, maybe this could help anyone with this similar problem.

Submitted by Tomas on

Permalink

It's the end of the year 2016, and this post just saved my SVN migration from a very old Ubuntu to RHEL 7. Thank you.

Add new comment

Plain text

  • Allowed HTML tags: <b> <i> <em> <strong> <blockquote> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

About This Blog

Photo of Peter RukavinaI am . I am a writer, letterpress printer, and a curious person.

To learn more about me, read my /nowlook at my bio, listen to audio I’ve posted, read presentations and speeches I’ve written, or get in touch (peter@rukavina.net is the quickest way). 

You can subscribe to an RSS feed of posts, an RSS feed of comments, or a podcast RSS feed that just contains audio posts. You can also receive a daily digests of posts by email.

Search