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

半腔热情 提交于 2019-12-02 16:57:28
anatoly techtonik

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 <foo@example.com>
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.

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

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.

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")

I ran into this problem too with dulwich.errors. Instead of installing everything from scratch. I just copied dulwich from my default site-packages to the mercurial site-packages. worked with no problems.

I got this error as well even after downloading the latest Tortoisehg and making sure the hggit plugin was installed as well as my .ini & hgrc files had the right entry to enable hggit.

Turns out my problem was that I had both mercurial and tortoisehg in my path. So when I ran any hg commands, it was using the hg.exe in mercurial folder as opposed to the hg.exe in the torsoisehg directory.

This makes sense but my mercurial installation did not have the plug ins. My fix was to remove mercurial from my path so hg commands go through the tortoisehg directory since it has hg completely bundled. Note however, the recommended option might be to upgrade mercurual to a version that has the plugins that one needs but this is what worked for me. I tried replacing the library.zip in mercurial with the one in tortoisehg and this worked but it led to other errors as one would imagine.

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

Recap: verify which hg exe is running your hg commands by checking your path because that hg.exe does not find the plugins for whatever reason.

Daniel K

Based on techtonik's explanation of the reason for the failing import of dulwich.errors, I found a solution which appears simpler to me than the already proposed ones:

On the Mercurial download page there is offered

Mercurial <x.y.z> for Python 2.7 on Windows x86 (source install)

and

Mercurial <x.y.z> for Python 2.7 on Windows x64 (source install)

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

If hg-git and dulwich have been installed to this Python installation as well, the import errors should vanish.

If you are not sure what to do now, I hope this step-by-step explanation helps:

Prerequisites

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

Steps

  1. Deinstall any existing Mercurial installation
  2. Download and install one of the above-quoted EXE files, depending on whether your Python 2.7 installation is 32bit or 64bit (If you get a "Python 2.7 cannot be found in registry" error, you probably need the other one.)

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

sudo apt-get install python-dev # Dam you dependency!

sudo easy_install dulwich

Success!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!