views:

784

answers:

5

I'm trying to use the hg-git Mercurial extension on Windows (Windows 7 64-bit, to be specific). I have Mercurial and Git installed. I have Python 2.5 (32-bit) installed.

I followed the instructions on http://hg-git.github.com/ to install the extension. The initial easy_install failed because it was unable to compile dulwich without Visual Studio 2003.

I installed dulwich manually by:

  • git clone git://git.samba.org/jelmer/dulwich.git
  • cd dulwich
  • c:\Python25\python setup.py --pure install

Now when I run easy_install hg-git, it succeeds (since the dulwich dependency is satisfied).

In my C:\Users\username\Mercurial.ini, I have:

[extensions]
hgext.bookmarks =
hggit =

When I type 'hg' at a command prompt, I see: "* failed to import extension hggit: No module named hggit"

Looking under my c:\Python25 folder, the only reference to hggit I see is Lib\site-packages\hg_git-0.2.1-py2.5.egg. Is this supposed to be extracted somewhere, or should it work as-is?

Since that failed, I attempted the "more involved" instructions from the hg-git page that suggested cloning git://github.com/schacon/hg-git.git and referencing the path in my Mercurial configuration. I cloned the repo, and changed my extensions file to look like:

[extensions]
hgext.bookmarks =
hggit = c:\code\hg-git\hggit

Now when I run hg, I see: * failed to import extension hggit from c:\code\hg-git\hggit: No module named dulwich.errors.

Ok, so that tells me that it is finding hggit now, because I can see in hg-git\hggit\git_handler.py that it calls

from dulwich.errors import HangupException

That makes me think dulwich is not installed correctly, or not in the path.

Update:

From Python command line:

import dulwich

yields Import Error: No module named dulwich

However, under C:\Python25\Lib\site-packages, I do have a dulwich-0.5.0-py2.5.egg folder which appears to be populated. This was created by the steps mentioned above. Is there an additional step I need to take to make it part of the Python "path"?

From Python command line (as suggested in one of the answers):

import pkg_resources
pkg_resources.require('dulwich')

yields [dulwich 0.5.0 (c:\python25\lib\site-packages\dulwich-0.5.0-py2.5.egg)]

So what does that tell me? Importing dulwich fails, but apparently pkg_resources can find it. What can I do with that information?

A: 

Until you get import dulwich to work, hggit won't work. Check that the dulwich egg file is in your easy-install.pth file under site-packages.

For further debugging you can try ask pkg_resources about it:

import pkg_resources
pkg_resources.require("dulwich")
David Fraser
This line is in my easy-install.pth file:/c/Python25/lib/site-packages/dulwich-0.5.0-py2.5.egg
Joshua Flanagan
I ran the pkg_resources command and put the results in the question above. Now what?
Joshua Flanagan
I can reproduce your exact result by easy_installing dulwich and removing it from easy-install.pthDid you manually edit the path in your easy-install - the /c/Python25 looks wrong - I'd replace that with a straight dulwich-0.5.0-py2.5.eggOr even better, remove the line and re-run easy_install dulwich
David Fraser
+1  A: 

Try following configuration (change to your path), which works for me:

[extensions]
; hg-git extention
hgext.bookmarks =
hggit = C:\Python26\Lib\site-packages\hg_git-0.2.1-py2.6.egg\hggit

In my case when I have empty value for hggit =, I get the same error as you do in this case. But I can import dulwich without problem in python shell, so you should check your easy-install.pth (as pointed out by David) if it contains dulwich-0.5.0-py2.5.egg. I did install pure version of dulwich as well.

van
Do I need to extract the egg for that to work? In my site-packages directory, I have that .egg file, but I do not have a directory named hg_git-0.2.1-py2.6.egg. Are you referencing hggit within the unexpanded egg file?
Joshua Flanagan
I do not have the egg file, and if I remember correctly the .egg file did not work properly on my machine. Then I installed using `-Z` parameter of `easy_install` in order to extract it during the installation. The same applies for `dulwich`. Hope it helps you.
van
This worked for me with Tortoise 1.0.3 Hg 1.5.3 installed. Make sure you use the -Z when you easy_install hg-git, and correct the hggit path above to whatever version it ends up downloading
David
+1  A: 

If you can install TortoiseHg, it includes dulwich and other requirements.

kuy
Yup, TortoiseHG is great for windows ...
Nikhil
I have TortoiseHg 1.0.3 and still got this error.
David
@David did you install other Mercurial executable? Please make sure your "hg" command points TortoiseHg's Mercurial executable. or try TortoiseHg 1.0.4.
kuy
@kuy I installed full Hg and got it working
David
+3  A: 

That makes me think dulwich is not installed correctly, or not in the path.

You're absolutely right. Mercurial binary distributions for Windows are 'frozen' - they use the Python code and interpreter bundled with them and therefore independent of packages installed in system PYTHONPATH. When you specify path to hggit extension in Mercurial.ini, hg tries to import it using direct path, but dulwich library is not imported explicitly by hg and doesn't bundled with its library, so the import fails.

It is possible to add both Dulwich and HgGit into library.zip that is installed along with hg.exe, but for me the best way is to install everything from source including Mercurial and execute commands using .bat files installed into \Python\Scripts. In this case you will need to:

  1. Install Mercurial from source. This builds "pure" version, because Windows users usually don't have Visual Studio or alternative compiler for compiling C speedups.
  2. Install Dulwich - I'd use latest trunk snapshot for both Git and Dulwich.

    python setup.py --pure install

  3. Install latest HgGit snapshot

    python setup.py install

  4. Edit Mercurial.ini to enable hggit =

  5. Launch Mercurial using your \Python\Scripts\hg.bat
techtonik
Finally! Thanks, that did it.
Joshua Flanagan
A: 

I cant get hg-git working at windows too.

Why there aren't any installer for hg-git and dulwich?

Ed Pichler