How do I correctly install dulwich to get hg-git working on Windows?

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


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

I found a simpler solution at http://candidcode.com/2010/01/12/a-guide-to-converting-from-mercurial-hg-to-git-on-a-windows-client/

And then I found a yet simpler solution myself:

To use the hg-git Mercurial extension on Windows:

  1. install the official Mercurial binaries
  2. put dulwich folder from dulwich sources and hggit folder from hg-git sources to the root of library.zip in Mercurial installation folder
  3. add the following to %USERPROFILE%\Mercurial.ini:

[extensions]
hgext.bookmarks=
hggit=

To have SSH support you need plink.exe from PuTTY family. After that you should add the following to Mercurial.ini:

[ui]
username = John Doe <[email protected]>
ssh=d:/home/lib/dll/plink.exe -i "d:/home2/ssh-private-key.ppk"

When connecting to a SSH server for the first time, you should start putty.exe and try to connect using it. It will add the server key fingerprint to the registry. Otherwise plink will ask you to accept the fingerprint but it doesn't accept any input.

You can use puttygen.exe to generate private keys. Either use keys without a passphrase or use Pageant.exe ssh authentication agent.