How to install dulwich correctly so that hg-git works on Windows?

I am trying to use the hq-git Mercurial extension on Windows (Windows 7 requires a 64-bit version). I have Mercurial and Git installed. I have Python 2.5 (32-bit) installed.

I followed the instructions at http://hg-git.github.com/ to install the extension. The original easy_install failed because it could not compile dulwich without Visual Studio 2003.

I installed dulwich manually:

  • 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 running).

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

[extensions] hgext.bookmarks = hggit = 

When I type 'hg' on the command line, I see: "*** failed to import the hggit extension: there is no module named hggit"

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

Since this failed, I tried to follow the “more attractive” instructions on the hg-git page, which suggested cloning git: //github.com/schacon/hg-git.git and a link to the path to my Mercurial configuration. I cloned the repo and modified the extensions file to look like this:

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

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

So this tells me that now it finds hggit, because I see in hg- git \ hggit \ git_handler.py that it calls

 from dulwich.errors import HangupException 

This makes me think that dulwich is installed incorrectly or not in the way.

Update:

From the Python command line:

 import dulwich 

gives Import Error: No module named dulwich

However, in the C: \ Python25 \ Lib \ site-packages folder, I have a dulwich-0.5.0-py2.5.egg folder, which seems to be populating. This was created by the steps above. Is there another step I should take to make it part of the Python “path”?

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

 import pkg_resources pkg_resources.require('dulwich') 

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

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

+48
python windows mercurial hg-git dulwich
Mar 02 '10 at 4:40
source share
9 answers

This makes me think that the dulwich is not installed correctly or not in the way.

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

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

  • Install Mercurial from source. This creates a “clean” version, as Windows users usually do not have Visual Studio or an alternative compiler to compile C accelerations.
  • Install Dulwich - I would use the last snapshot for both Git and Dulwich.

    python setup.py --pure install

  • Install the latest hgGit snapshot

    install python setup.py

  • Modify Mercurial.ini to include hggit =

  • Launch Mercurial using your \ Python \ Scripts \ hg.bat
+16
Apr 28 '10 at 10:25
source share

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 an even simpler solution:

To use the hg-git Mercurial extension on Windows:

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



 [extensions] hgext.bookmarks= hggit= 

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

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

The first time you connect to the SSH server, you must run putty.exe and try to connect to it. It will add the server key fingerprint to the registry. Otherwise, plink will ask you to accept the fingerprint, but it will not accept any input.

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

+10
Aug 09 2018-11-18T00:
source share

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

+8
Apr 02 2018-10-12T00:
source share

Try the following configuration (changing your path) that 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 an empty value for hggit = , I get the same error as in this case. But I can import dulwich without problems in the 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 also installed a clean version of dulwich .

+4
Mar 23 '10 at 22:37
source share

Until you get import dulwich , hggit will not work. Make sure the dulwich egg file is in the easy-install.pth in the site-packages section.

For further debugging you can ask pkg_resources about this:

 import pkg_resources pkg_resources.require("dulwich") 
0
Mar 12 '10 at 11:48
source share

I ran into this problem and with dulwich.errors. Instead of installing everything from scratch. I just copied dulwich from my default site packages to mercury site packages. worked without problems.

0
Nov 22 '10 at 5:12
source share

Based on the techtonik explanation of the reason for the failed import of dulwich.errors , I found a solution that seems simpler to me than the ones already offered:

The Mercurial download page offers

Mercurial <xyz> for Python 2.7 on Windows x86 (initial installation)

and

Mercurial <xyz> for Python 2.7 on Windows x64 (initial installation)

as .EXE files that install Mercurial as a Python module in an existing Python 2.7 installation (x86 or x64).

If hg-git and dulwich were installed on this Python installation, the import errors should go away.

If you don’t know what to do now, I hope this step-by-step explanation helps:

Preconditions

  • Python 2.7 installed
  • <python 2.7 install dir> and <python 2.7 install dir>\Scripts are in the PATH environment variable
  • hg-git (and dulwich) were installed into this Python installation using the instructions here

Actions

  • Remove any existing Mercurial installation.
  • Download and install one of the above EXE files, depending on whether your Python 2.7 installation is set to 32-bit or 64-bit (if you get the error "Python 2.7 cannot be found in the registry", you probably need other).

Now hg clone <some git repo> should work on the console.

0
Jan 22 '14 at 1:43
source share

I got this error even after downloading the latest version of Tortoisehg, and make sure the hggit plugin was installed, and also my .ini and hgrc files had the correct entry to enable hggit.

It turns out that my problem was that I had both mercury and tortie on my way. Therefore, when I ran any hg commands, it used hg.exe in the mercurial folder, not hg.exe in the torsoisehg directory.

This makes sense, but there were no plug-ins in my mercury installation. My fix was to remove mercury from my path so that the hg commands go through the tortoise tree directory, as it is completely linked to hg. Please note, however, the recommended option might be to upgrade mercurual to the version with the plugins you need, but this is what worked for me. I tried replacing library.zip in mercurial with the one in tortoisehg, and it worked, but it led to other errors, as you might imagine.

@techtonik's answer led me along this road, for which I am grateful.

Recap: check which hg exe runs your hg commands by checking your path, because hg.exe does not find plugins for any reason.

0
Feb 01 '16 at 20:21
source share

sudo apt-get install python-dev # Bad addiction to you!

sudo easy_install dulwich

Success!

-2
Aug 14 '13 at 19:06 on
source share



All Articles