How do I correctly install dulwich to get hg-git w

2019-03-08 17:50发布

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?

9条回答
霸刀☆藐视天下
2楼-- · 2019-03-08 18:01

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")
查看更多
▲ chillily
3楼-- · 2019-03-08 18:08

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

查看更多
贪生不怕死
4楼-- · 2019-03-08 18:14

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.

查看更多
Viruses.
5楼-- · 2019-03-08 18:14

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.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-03-08 18:14

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.

查看更多
Fickle 薄情
7楼-- · 2019-03-08 18:16

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

sudo easy_install dulwich

Success!

查看更多
登录 后发表回答