挂钩到mercurial的pretxncommit,无法导入requests模块?

2 投票
1 回答
725 浏览
提问于 2025-04-17 18:08

你好,我正在尝试在 Mercurial 的 pretxncommit Python 文件中进行一些操作。
我的大部分代码运行得很好,但我遇到了这个错误:

错误:pretxncommit.pcrcheck 钩子引发了一个异常:没有名为 requests 的模块,事务中止!回滚完成,终止:没有名为 requests 的模块!

我想使用 requests.get。在我另一个独立的 Python 文件中,import requests 可以正常工作,但把它放到 Mercurial 中就出现了问题,似乎无法导入这个模块。
这是可能的吗?

1 个回答

1

所以我最后不得不添加这些东西,哈哈。你需要把外部包的路径加到Mercurial正在使用的路径上。(http://tortoisehg.bitbucket.io/manual/2.9/faq.html) 是的,看起来这些都是让requests模块正常工作的必要条件,没有它们我一直遇到不同的导入错误。

这是我添加的内容:

import sys
sys.path.append(r'C:\\Python27\\Lib\\site-packages\\')
sys.path.append(r'C:\\Python27\\Lib\\')
sys.path.append(r'C:\\Python27\\Lib\\site-packages\\requests-1.1.0-py2.7.egg\\')
sys.path.append(r'C:\\Python27\\Lib\\site-packages\\simplejson-3.1.0-py2.7.egg\\simplejson')
sys.path.append(r'C:\\Python27\\Lib\\site-packages\\simplejson-3.1.0-py2.7.egg\\')
sys.path.append(r'C:\\Python27\\Lib\\site-packages\\simplejson-3.1.0-py2.7.egg\\simplejson\\tests\\')

撰写回答