安装TortoiseHg for mac:没有名为mercurial的模块

时间:2013-01-06 14:44:18

标签: python mercurial python-2.7 tortoisehg

我正在尝试按照以下说明安装TortoiseHg for Mac:https://bitbucket.org/tortoisehg/thg/wiki/developers/MacOSX#!alternative-install-via-macports

我正在尝试按照“替代方案:通过Homebrew安装”的说明,我有一个问题。

当我按照它的工作说明执行./thg log时,TortoiseHg正在启动。但是,当我尝试从python脚本创建一个应用程序时,应用程序已创建,但是当我启动它时,它会崩溃。

这是输出:

Traceback (most recent call last):
  File "/Users/fabienhenon/Documents/thg-mac-app/dist/TortoiseHg.app/Contents/Resources/__boot__.py", line 316, in <module>
    _run()
  File "/Users/fabienhenon/Documents/thg-mac-app/dist/TortoiseHg.app/Contents/Resources/__boot__.py", line 311, in _run
    exec(compile(source, path, 'exec'), globals(), globals())
  File "/Users/fabienhenon/Documents/thg-mac-app/dist/TortoiseHg.app/Contents/Resources/main.py", line 28, in <module>
    imp.load_source("thg", SCRIPT_DIR + "/bin/thg")
  File "/Users/fabienhenon/Documents/thg-mac-app/dist/TortoiseHg.app/Contents/Resources/bin/thg", line 56, in <module>
    from mercurial import demandimport
ImportError: No module named mercurial
2013-01-06 12:25:17.436 TortoiseHg[406:707] TortoiseHg Error
logout

[Opération terminée]

当我输入:hg --version时,我有以下输出:

Mercurial Distributed SCM (version 2.4.2+20130102)
(see http://mercurial.selenic.com for more information)

Copyright (C) 2005-2012 Matt Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

有人可以帮我解决这个问题吗?

感谢您的回答

1 个答案:

答案 0 :(得分:3)

我找到了解决此问题的解决方案。

从我的错误消息中,脚本找不到名为mercurial的模块。我是Python的新手,所以我不得不做一些研究来了解模块导入是如何工作的,我发现了一些关于使用'sys'模块动态导入模块的东西。

我的解决方案是编辑tortoisehg源代码(错误来自的文件),以动态地将我的mercurial模块的路径添加到'sys.path',以便程序知道在哪里找到mercurial模块。 / p>

这是代码(在'thg'python文件中,第56行(如错误所述)):

import sys
sys.path.append("/Library/Python/2.7/site-packages")

您必须在此行之前添加此代码:

from mercurial import demandimport

路径必须与mercurial文件夹的位置相对应。