Skip to main content
 首页 » 编程设计

python之连接到 mercurial pretxncommit。并且不能导入请求模块

2025年05月04日9小虾米

您好,我正在尝试连接到 mercurial pretxncommit python 文件。
我的大部分代码工作正常,但出现此错误:

error: pretxncommit.pcrcheck hook raised an exception: No module named requests transaction abort! rollback completed abort: No module named requests!

我正在尝试使用 requests.get。 import requests 在我制作的另一个独立的 python 文件中工作正常,但似乎将其挂接到 mercurial 导致无法导入此模块的问题。
这可能吗?

请您参考如下方法:

所以我最终不得不添加所有这些哈哈。您必须将外部包的路径添加到 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\\')