Tag: mercurial

Fix “import mercurial” problem in windows

Hi guys, it’s been a while since my last post, this time I want to share a tiny tip that saved me from a huge headache.

At work we’re planning on using Trac to manage our project (mainly as an issue tracker) along with Mercurial. Mercurial is great, all distributed version control systems rock, but when we chose mercurial it just seemed like the right decision due to it’s excellent performance and relative ease to integrate with Apache.

In any case, today I installed trac on our server computer, which unfortunately is a Windows machine. Unfortunate because setting things up on Windows is a bit more troublesome than on Linux or even Mac.

Once Trac was up and running along with our Mercurial server, both under Apache thanks to mod_wsgi, I installed the TracMercurial plugin so that I could setup our Mercurial repository in Trac. But even after adding the repo, I could not even browse the repo.

After reading a couple of posts, I found out that I had to check if the mercurial module could be imported in a normal python prompt. And so

>> import mercurial

… returned a module not found error.

Quick fix

Because I installed Selenic’s official windows binaries, the mercurial module is kept safe in the program files folder, where only the hg.exe binary can access it.

To fix this, I just copied the mercurial folder that was in c:\program files\mercurial\lib\mercurial into Python’s site-packages folder (C:\python26\lib\site-packages when using python 2.6).

And after restarting apache, I could see the “browse source” tab in Trac and all was good!

Note: I know, this is kind of BARBARIC, I could have added mercurial’s path into the PYTHON_PATH, but I just didn’t want to mix all those modules…