在Win7上为Apache设置Mercurial时出错 - DLL加载失败
我正在尝试在Windows 7电脑上设置Mercurial,并通过Apache进行发布。以下是我所遵循的步骤:
- 安装了Mercurial,文件名是mercurial-2.0.0-x86.msi。
- 安装了Apache服务器,文件名是httpd-2.2.21-win32-x86-openssl-0.9.8r.msi。
- 安装了Python,文件名是python-2.6.1.msi。
- 通过mod_wsgi设置Apache使用Python,文件名是mod_wsgi-win32-ap22py26-3.3.so。到这里,Apache启动得很好。
- 创建了一个名为D:\hg\scripts的文件夹。
- 将Mercurial自带的library.zip解压到D:\hg\scripts\library_hg。
- 把Mercurial中的templates文件夹复制到D:\hg\scripts\library_hg\templates。
- 在D:\hg\hgrepos\demo1中设置了一个演示仓库。
创建了一个D:\hg\scripts\hgweb.config文件。内容如下:
# An example WSGI for use with mod_wsgi, edit as necessary # An example WSGI for use with mod_wsgi, edit as necessary # See https://www.mercurial-scm.org/wiki/modwsgi for more information # Path to repo or hgweb config to serve (see 'hg help hgweb') config = "D:/hg/scripts/hgweb.config" # Uncomment and adjust if Mercurial is not installed system-wide: import sys; sys.path.insert(0, "D:/hg/scripts/library_hg"); #print sys.path; # Uncomment to send python tracebacks to the browser if an error occurs: #import cgitb; cgitb.enable() # enable demandloading to reduce startup time #from mercurial import demandimport; demandimport.enable() from mercurial.hgweb import hgweb application = hgweb(config)
我的D:\hg\scripts\hgweb.config文件内容是:
[web] style = coal [paths] / = D:/hgrepos/*
我的Apache配置文件httpd.conf的内容是:
WSGIScriptAlias /hg "D:/hg/scripts/hgweb.wsgi" <Directory "D:/hg/hgrepos"> Order deny,allow Allow from all </Directory> <Directory "D:/hg/scripts/"> Options ExecCGI FollowSymlinks AddHandler wsgi-script .wsgi AllowOverride None Order allow,deny Allow from all </Directory>
当我尝试访问hg脚本 http://localhost:9000/hg 时,出现了以下错误:
mod_wsgi (pid=3492): Target WSGI script 'D:/hg/scripts/hgweb.wsgi' cannot be loaded as Python module. mod_wsgi (pid=3492): Exception occurred processing WSGI script 'D:/hg/scripts/hgweb.wsgi'. Traceback (most recent call last): File "D:/hg/scripts/hgweb.wsgi", line 17, in <module> from mercurial.hgweb import hgweb File "mercurial\\hgweb\\__init__.pyc", line 10, in <module> File "mercurial\\hgweb\\hgweb_mod.pyc", line 10, in <module> File "mercurial\\ui.pyc", line 8, in <module> File "mercurial\\i18n.pyc", line 8, in <module> File "mercurial\\encoding.pyc", line 9, in <module> File "unicodedata.pyc", line 12, in <module> File "unicodedata.pyc", line 10, in __load ImportError: DLL load failed: The specified module could not be found.
我几乎对Python没有任何了解。我一直在各种论坛上寻找这个错误的原因,但没有成功。如果有人能给我指个方向,我将非常感激。
2 个回答
从 https://www.mercurial-scm.org/downloads 这个网站上,你需要下载 Python 2.6 的安装包。然后,把 D:\hg\scripts\library_hg 这个文件夹删掉,因为安装这个包后它会占用空间。另外,你可以把代码里 import sys 这一行注释掉。
还有,在你的配置文件里,要用 [collections],而不是 [paths](也不要加 *)。
虽然可能不需要,但如果你遇到除了无法加载模块以外的错误,可以把 hgweb.wsgi 文件的最后两行替换成下面的内容:
from mercurial import demandimport; demandimport.enable()
from mercurial.hgweb import hgweb, wsgicgi
application = hgweb(config)
wsgicgi.launch(application)
我花了好几天试图找解决办法,结果放弃了。 我也尝试在Windows上构建mercurial,但没有成功。
我在Python命令行中运行了和hgweb.wsgi里一样的命令,但没有遇到DLL错误。我觉得这个讨论串说明了问题出在Python的发行版上,而不是mercurial本身: http://groups.google.com/group/modwsgi/browse_thread/thread/fa72de2deef276d9
出于某种原因,通过Apache和mod_wsgi运行的Python无法在Windows上找到DLL文件。