IIS 7.5上Mercurial和hgweb - python错误

9 投票
4 回答
7408 浏览
提问于 2025-04-16 08:02

我正在尝试在IIS 7.5(Windows 7 64位)上运行Mercurial,但遇到了一个我无法解决的错误。

我按照Jeremy Skinner的教程进行了操作,链接在这里:Mercurial on IIS7

因为我使用的是Mercurial 1.7.2,所以我用的是hgweb,而不是hgwebdir。

我已经安装并配置好了Python。我在IIS上为Mercurial设置了一个应用,地址是http://localhost/hg,对应的目录是c:\inetpub\wwwroot\hg。

我把模板目录放到了c:\inetpub\wwwroot\hg,并且把library.zip文件解压到了c:\inetpub\wwwroot\hg。

但是当我访问这个网站时,出现了一个错误:> 文件 "C:\inetpub\wwwroot\hg\hgweb.cgi",第15行,来自mercial import demandimport; demandimport.enable() 导入错误:没有名为mercurial的模块。

在搜索这个错误时,我找到了以下答案:https://stackoverflow.com/questions/2123798/

根据接受的答案,我把我的hgweb.cgi改成了这样:

#!c:/python/python26/python.exe
#
# An example hgweb CGI script, edit as necessary
# See also https://www.mercurial-scm.org/wiki/PublishingRepositories

# Path to repo or hgweb config to serve (see 'hg help hgweb')
config = "/path/to/repo/or/config"

# Uncomment and adjust if Mercurial is not installed system-wide:
import sys; sys.path.insert(0, "c:\inetpub\wwwroot\hg")

# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb; cgitb.enable()

from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb, wsgicgi
application = hgweb('c:\inetpub\wwwroot\hg\hgweb.config')
wsgicgi.launch(application)

做完这些后,我还是遇到了同样的错误。我不知道该怎么做了。任何帮助都将非常感激。

补充1:根据要求,c:\inetpub\wwwroot\hg的截图:My Hg directory

4 个回答

3

我写了一份关于如何在IIS7上设置Mercurial仓库的最新说明,使用的是当前版本的Mercurial(1.8.x)和Python(2.7)。你可以在这里查看详细的步骤:设置说明

这份说明对你会有帮助,如果你觉得有用,麻烦给这个答案投个赞(或者踩也行;)

3

Adam Boddington 写了一篇更新的安装说明,现在可以正常使用了:http://stackingcode.com/blog/2011/02/24/running-a-mercurial-server-on-iis-7-5-windows-server-2008-r2

15

我这周一直在为这个设置而苦恼。

看起来他们最近对在IIS中使用Mercurial的方式做了一些重大改动,所以上面链接的Jeremy Skinner的教程在1.7.2版本上可能会有问题。

这是一个更新的链接,我发现我需要做一些不同的操作。

这些说明适用于1.7.x版本,如果你使用的是1.8.x版本,记得查看Ethan的评论!

我按照/contrib/win32/hgwebdir_wsgi.py的评论中的说明进行了操作。

  • 安装Python 2.6.6

  • 把Python添加到系统的PATH中(这样会方便很多)

  • 安装pywin32 v214(使用Python安装程序,重要!)(注意这是针对Python 2.6构建的)

  • 安装isapi_wsgi

  • 下载Mercurial源代码包
    解压后运行

    python setup.py --pure build_py -c -d . build_ext -i build_mo --force
    python setup.py --pure install --force
    
  • 把hgwebdir_wsgi.py从/contrib/win32复制到你想要托管的文件夹中。

  • 在你要托管的文件夹中创建一个hgweb.config文件,并添加以下内容

    [paths]
    yourRepoName = c:\yourRepoLocation
    
  • 编辑hgwebdir_wsgi.py,使其指向hgweb.config。path_prefix如果hg是网站的根目录,则为0。如果你把它放在一个深度为1的虚拟目录中,则为1,以此类推。

  • 运行python hgwebdir_wsgi.py来创建isapi dll _hgwebdir_wsgi.dll。控制台应该会打印出“安装完成”。

  • 在IIS中创建你的应用池(不使用托管代码)

  • 创建你的网站,文件夹设置为与hgwebdir_wsgi.py相同的文件夹。

  • 添加类型为模块的处理程序,使用“*”作为映射,选择_hgwebdir_wsgi.dll作为可执行文件,选择isapimodule作为类型,Mercurial-ISAPI作为名称(虽然名称其实不太重要)。

  • 编辑模块的功能权限以允许执行。

web.config(针对前面两个步骤):

<system.webServer>
<handlers accessPolicy="Read, Execute, Script">
<add name="Mercurial-Isapi" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\inetpub\hgweb\_hgwebdir_wsgi.dll" resourceType="Unspecified" />
</handlers>
</system.webServer>

经过这些步骤后,我终于让它工作了。

最后一件事,我确实把MFC71.dll复制到了windows/system32,虽然我不确定这是否必要。http://python.net/crew/skippy/win32/

我认为我这里和上面链接的主要区别在于,我做了“纯Python”的Mercurial安装,虽然我对Python完全是个新手,所以不太确定。此外,我为pywin和isapi_wsgi做了“Python安装”,而不是普通的Windows安装包。

撰写回答