繁体   English   中英

在TRACE上使用Mercurial时,这一次在Windows 2008 R2(64位)上,在“需求导入”中获取“ DLL加载失败”或python异常

[英]Getting either “DLL load failed” or python-exception in demandimport, when using mercurial on trac, this time on Windows 2008 R2, 64 bit

这个问题是在2011年提出的,并且在不同的操作系统(XP而不是WSRV2008R2)上听起来很相似,但是公认的解决方案是返回到较古老的水银版本1.8。 我认为这不是2012年的好答案。

我想知道是否有一种方法可以使Apache 2.2和Trac 0.12,以及Mercurial 2.2.2在Windows上运行,并且都在Apache下运行。 我遇到的问题似乎与Python编程有关,并且与各种压缩和未压缩模块格式的Python使用以及Mercurial使用有关。

  1. 似乎要使所有这些正常工作,可能需要您在Windows上从源代码构建Mercurial,或使用Mercurial的“纯python”版本。 我想知道Python或Mercurial会导致这些问题,这些问题可能需要我运行“纯python”。 也许一个公认的答案是Mercurial是一种古怪的野兽,在mod_wsgi下,应该只使用纯Python版本的mercurial。 底层的Python和软件实现的原因也很重要。

  2. 似乎暗示了Mercurial的幕后需求加载功能,这是Mercurial源码中的源代码级功能,这使我感到困惑,我希望有人能对此进行解释。

  3. 在Mercurial已安装版本中使用“ library.zip”似乎也造成了运行时的情况,当我从命令行运行python.exe(Windows中的命令提示符,设置了环境和路径)时,Mercurial将导入(如果我在apache中,则将被设置),但是Mercurial的主要python单元不会使用mod_wsgi从apache中导入。

这是我使用的测试脚本,在命令提示符下工作正常,并显示此python 2.6实例在site-packages具有一组可行的Mercurial内容:

from mercurial import ui, hg
path = 'D:/MyHgRepo'
repo = hg.repository(ui.ui(), path)
print path,"Repository info:"
print repr(repo), "object len: ",len(repo)

但是,当从Apache内托管的Trac内部运行时,尝试加载Mercurial模块的尝试失败,首先是由于一个奇怪的demandimport失败,并且在修复该问题时,无故默默地在Trac中给出了原因(我将不得不在trac中进行调试)解决此问题的源代码,也许)。 Demandimport.py是site-packages / Mercurial文件夹中的一个模块。 此异常回溯来自trac.log:

在这两种情况下,它都会Look in the Trac log for more information. -这里的错误消息似乎是问题所在:

Traceback (most recent call last):
  File "build\bdist.win32\egg\trac\loader.py", line 68, in _load_eggs
    entry.load(require=True)
  File "build/bdist.linux-i686/egg/pkg_resources.py", line 1954, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "C:\Program Files\BitNami Trac Stack\python\lib\site-packages\mercurial\demandimport.py", line 114, in _demandimport
    mod = _origimport(name, globals, locals)
  File "build\bdist.win32\egg\trac\mimeview\rst.py", line 155, in <module>
  File "C:\Program Files\BitNami Trac Stack\python\lib\site-packages\mercurial\demandimport.py", line 87, in __getattribute__
    return getattr(self._module, attr)
AttributeError: 'module' object has no attribute 'directives'

上述异常可以通过“注释掉”整个需求导入单元来解决,这很奇怪。 这是我的空“ pass”实现:

# demandimport.py - disabled by warren.

'''
demandimport - disabled in code by warren.
'''

def enable():
    "does nothing"
    pass

def disable():
    "does nothing"
    pass 

上面的hack清除了上面可见的异常,使trac.log中没有错误,但是,Trac中仍然没有可见的Hg插件。

通过互联网上的谷歌搜索,我发现:

  1. 安装到\\ Python2.6系统文件夹中的Windows的Mercurial安装程序附带一个“ Library.zip”,其中不仅包含.pyc,还包含.pyd文件。 当在apache下使用mod_wsgi而不是交互式使用Python或通过独立的http hg serve操作时,这似乎对某些人有效,而对某些人无效。 我已经看到Trac Mercurial插件的作者建议拆包library.zip。 这是我的第一个问题; Library.zip是怎么回事,这是我的问题。

  2. 很多人很难在Windows上从Apache内部运行Python 2.6或2.7,mod_wsgi,Trac和Mercurial。 它们的潜在问题似乎远远超出了软件用户和安装人员的解决能力,并且需要一些奥术,或者至少是基本的python编程知识来解决。

这就是为什么我在编程答案网站上问这个问题的原因。 我想了解Python,以及流行的开源软件包Mercurial,Trac等使用的Python及其库,模块和站点软件包的体系结构,以便可以理解,诊断和调试Mercurial 2.2损坏的Python代码库,在mod_wsgi / apache2.2环境中使用时,在我的系统上不起作用。

我正在使用Python 2.6和Trac 0.12,它们都是由Bitnami Trac Stack安装程序安装的。 我正在使用通过Merurial网站上的mercurial-2.2-for-x86-for-Python2.6安装程序安装的Mercurial 2.2。

发生这种情况是因为安装了带有二进制文件(包括一些CPython扩展名)的Mercurial版本无法导入到Web服务器WSGI或CGI或其他Python-in-apache技术内部使用的Python版本中。

解:

A.查找并安装正确版本的Mercurial二进制文件(包括Mercurial使用的library.zip和CPython二进制扩展名)

B.选择Mercurial的纯100%-python(无CPython二进制扩展名)版本,例如可破解的mercurial:

https://www.mercurial-scm.org/wiki/HackableMercurial

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM