如何正确安装 dulwich 以使 hg-git 在 Windows 上工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2360944/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I correctly install dulwich to get hg-git working on Windows?
提问by Joshua Flanagan
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.
我正在尝试在 Windows(Windows 7 64 位,具体来说)上使用 hg-git Mercurial 扩展。我安装了 Mercurial 和 Git。我安装了 Python 2.5(32 位)。
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.
我按照http://hg-git.github.com/上的说明安装扩展。最初的 easy_install 失败,因为它无法在没有 Visual Studio 2003 的情况下编译 dulwich。
I installed dulwich manually by:
我通过以下方式手动安装了德威:
- git clone git://git.samba.org/jelmer/dulwich.git
- cd dulwich
- c:\Python25\python setup.py --pure install
- git 克隆 git://git.samba.org/jelmer/dulwich.git
- 德威
- c:\Python25\python setup.py --pure 安装
Now when I run easy_install hg-git, it succeeds (since the dulwich dependency is satisfied).
现在,当我运行 easy_install hg-git 时,它成功了(因为满足了 dulwich 依赖项)。
In my C:\Users\username\Mercurial.ini, I have:
在我的 C:\Users\username\Mercurial.ini 中,我有:
[extensions]
hgext.bookmarks =
hggit =
When I type 'hg' at a command prompt, I see: "*** failed to import extension hggit: No module named hggit"
当我在命令提示符下键入 'hg' 时,我看到:“*** 未能导入扩展 hggit:没有名为 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?
在我的 c:\Python25 文件夹下查看,我看到的对 hggit 的唯一引用是Lib\site-packages\hg_git-0.2.1-py2.5.egg
. 这是应该在某个地方提取的,还是应该按原样工作?
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:
由于失败了,我尝试了 hg-git 页面中的“更复杂”的说明,建议克隆 git://github.com/schacon/hg-git.git 并在我的 Mercurial 配置中引用路径。我克隆了 repo,并将我的扩展文件更改为如下所示:
[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.
现在,当我运行 hg 时,我看到:*** 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
好的,这告诉我它现在正在查找 hggit,因为我可以在 hg-git\hggit\git_handler.py 中看到它调用
from dulwich.errors import HangupException
That makes me think dulwich is not installed correctly, or not in the path.
这让我觉得 dulwich 没有正确安装,或者不在路径中。
Update:
更新:
From Python command line:
从 Python 命令行:
import dulwich
yields Import Error: No module named dulwich
产量 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"?
但是,在 C:\Python25\Lib\site-packages 下,我确实有一个似乎已填充的 dulwich-0.5.0-py2.5.egg 文件夹。这是通过上述步骤创建的。我是否需要采取额外的步骤才能使其成为 Python“路径”的一部分?
From Python command line (as suggested in one of the answers):
从 Python 命令行(如其中一个答案中所建议):
import pkg_resources
pkg_resources.require('dulwich')
yields [dulwich 0.5.0 (c:\python25\lib\site-packages\dulwich-0.5.0-py2.5.egg)]
产量 [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?
那么这告诉我什么呢?导入 dulwich 失败,但显然 pkg_resources 可以找到它。我可以用这些信息做什么?
采纳答案by anatoly techtonik
That makes me think dulwich is not installed correctly, or not in the path.
这让我觉得 dulwich 没有正确安装,或者不在路径中。
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.
你是绝对正确的。适用于 Windows 的 Mercurial 二进制发行版是“冻结的”——它们使用与它们捆绑在一起的 Python 代码和解释器,因此独立于系统 PYTHONPATH 中安装的包。当您在 Mercurial.ini 中指定 hggit 扩展名的路径时,hg 尝试使用直接路径导入它,但 dulwich 库不是由 hg 明确导入的,也没有与其库绑定,因此导入失败。
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:
可以将 Dulwich 和 HgGit 添加到与 hg.exe 一起安装的 library.zip 中,但对我来说,最好的方法是从源代码安装所有内容,包括 Mercurial,并使用安装在 \Python\Scripts 中的 .bat 文件执行命令。在这种情况下,您需要:
- Install Mercurialfrom source. This builds "pure" version, because Windows users usually don't have Visual Studio or alternative compiler for compiling C speedups.
Install Dulwich - I'd use latest trunk snapshotfor both Git and Dulwich.
python setup.py --pure install
Install latest HgGit snapshot
python setup.py install
Edit Mercurial.ini to enable
hggit =
- Launch Mercurial using your \Python\Scripts\hg.bat
- 从源代码安装 Mercurial。这会构建“纯”版本,因为 Windows 用户通常没有用于编译 C 加速的 Visual Studio 或替代编译器。
安装 Dulwich - 我会为 Git 和 Dulwich使用最新的主干快照。
python setup.py --pure 安装
安装最新的 HgGit快照
python setup.py 安装
编辑 Mercurial.ini 以启用
hggit =
- 使用您的 \Python\Scripts\hg.bat 启动 Mercurial
回答by nponeccop
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/
我在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:
在 Windows 上使用 hg-git Mercurial 扩展:
- install the official Mercurial binaries
- put dulwich folder from dulwich sources and hggit folder from hg-git sources to the root of library.zip in Mercurial installation folder
- add the following to %USERPROFILE%\Mercurial.ini:
- 安装官方 Mercurial 二进制文件
- 将 dulwich 源中的 dulwich 文件夹和 hg-git 源中的 hggit 文件夹放入 Mercurial 安装文件夹中 library.zip 的根目录
- 将以下内容添加到 %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:
要获得 SSH 支持,您需要 PuTTY 系列的 plink.exe。之后,您应该将以下内容添加到 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.
首次连接SSH服务器时,应启动putty.exe并尝试使用它进行连接。它将服务器密钥指纹添加到注册表中。否则 plink 会要求您接受指纹但它不接受任何输入。
You can use puttygen.exe to generate private keys. Either use keys without a passphrase or use Pageant.exe ssh authentication agent.
您可以使用 puttygen.exe 生成私钥。要么使用没有密码短语的密钥,要么使用 Pageant.exe ssh 身份验证代理。
回答by kuy
If you can install TortoiseHg, it includes dulwich and other requirements.
如果可以安装 TortoiseHg,则包括 dulwich 和其他要求。
回答by van
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.
在我的情况下,当我有空值时hggit =
,我得到与你在这种情况下相同的错误。但是我可以import dulwich
在 python shell 中没有问题,所以你应该检查你的easy-install.pth
(如大卫所指出的)是否包含dulwich-0.5.0-py2.5.egg
. 我也安装了纯版本dulwich
。
回答by David Fraser
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
.
在你开始import dulwich
工作之前,hggit
不会工作。检查dulwich
egg 文件是否在您的easy-install.pth
文件中site-packages
。
For further debugging you can try ask pkg_resources
about it:
为了进一步调试,您可以尝试询问pkg_resources
它:
import pkg_resources
pkg_resources.require("dulwich")
回答by Marco
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.
我在使用 dulwich.errors 时也遇到了这个问题。而不是从头开始安装所有东西。我只是将 dulwich 从我的默认站点包复制到 mercurial 站点包。没有问题。
回答by Daniel K
Based on techtonik's explanationof the reason for the failing import of dulwich.errors
, I found a solution which appears simpler to me than the already proposed ones:
根据 techtonik对导入失败原因的解释dulwich.errors
,我找到了一个对我来说比已经提出的解决方案更简单的解决方案:
On the Mercurial download pagethere is offered
在Mercurial 下载页面上,提供了
Mercurial
<x.y.z>
for Python 2.7 on Windows x86 (source install)
<x.y.z>
适用于 Windows x86 上的 Python 2.7 的Mercurial (源代码安装)
and
和
Mercurial
<x.y.z>
for Python 2.7 on Windows x64 (source install)
<x.y.z>
适用于 Windows x64 上的 Python 2.7 的Mercurial (源安装)
as .EXE files which install Mercurial as a Python moduleinto an existing Python 2.7 (x86 or x64) installation.
作为将 Mercurial 作为 Python 模块安装到现有 Python 2.7(x86 或 x64)安装中的.EXE 文件。
If hg-git and dulwich have been installed to this Python installation as well, the import errors should vanish.
如果 hg-git 和 dulwich 也已安装到此 Python 安装中,则导入错误应该会消失。
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 thePATH
environment variable- hg-git (and dulwich) have been installed into this Python installation via the instructions from here
- 安装了 Python 2.7
<python 2.7 install dir>
并且<python 2.7 install dir>\Scripts
在PATH
环境变量中- hg-git(和 dulwich)已通过此处的说明安装到此 Python 安装中
Steps
脚步
- Deinstall any existing Mercurial installation
- 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.)
- 卸载任何现有的 Mercurial 安装
- 下载并安装上面引用的 EXE 文件之一,具体取决于您的 Python 2.7 安装是 32 位还是 64 位(如果您收到“在注册表中找不到 Python 2.7”错误,您可能需要另一个。)
Now hg clone <some git repo>
should work on the console.
现在hg clone <some git repo>
应该在控制台上工作。
回答by delloPiro
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.
即使在下载最新的 Tortoisehg 并确保安装了 hggit 插件以及我的 .ini 和 hgrc 文件具有启用 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.
事实证明,我的问题是我的道路上同时有 mercurial 和 tortoisehg。因此,当我运行任何 hg 命令时,它使用的是 mercurial 文件夹中的 hg.exe,而不是 torsoisehg 目录中的 hg.exe。
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.
这是有道理的,但我的 mercurial 安装没有插件。我的解决方法是从我的路径中删除 mercurial,以便 hg 命令通过 tortoisehg 目录,因为它已经完全捆绑了 hg。但是请注意,推荐的选项可能是将 mercurual 升级到具有所需插件的版本,但这对我有用。我尝试将 mercurial 中的 library.zip 替换为 tortoisehg 中的 library.zip 并且这有效,但它导致了人们想象的其他错误。
@techtonik's answer led me down this road for which I am grateful.
@techtonik 的回答让我走上了这条路,对此我深表感谢。
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.
回顾:通过检查您的路径来验证哪个 hg exe 正在运行您的 hg 命令,因为无论出于何种原因,该 hg.exe 都找不到插件。
回答by Thierry
sudo apt-get install python-dev # Dam you dependency!
sudo easy_install dulwich
sudo apt-get install python-dev # 依赖你!
须藤easy_install 德威
Success!
成功!