Python无法打开msvcr90.dll

n. *_* m. 4 python dll python-2.6 msvcr90.dll

我的Windows应用程序嵌入了Python 2.6(旧的我知道,但这是我们必须使用的).它可以运行基本的Python命令,但无法尝试执行

import ctypes
ctypes.WinDLL("msvcr90.dll")
Run Code Online (Sandbox Code Playgroud)

我收到错误126"无法找到DLL".如果我种植应用程序可以找到它的DLL,那么我得到错误1114"DLL初始化例程失败".

更新这可以通过这个最简单的程序重现:

#include <math.h>
#include <iostream>
#undef _DEBUG
#include <Python.h>

int main(int argc, char* argv[])
{
    Py_SetProgramName(argv[0]);
    Py_Initialize();
    PyRun_SimpleString("import pyreadline\n");
    Py_Finalize();
    std::cout << "Press enter: " << std::endl;
    char c;
    std::cin.read(&c, 1);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在x86和amd64体系结构中使用V9或v10工具链进行编译时,这会失败.

回溯如下:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Python26-x86\lib\site-packages\pyreadline\__init__.py", line 9, in <m
odule>
    import unicode_helper, logger, clipboard, lineeditor, modes, console
  File "C:\Python26-x86\lib\site-packages\pyreadline\console\__init__.py", line
14, in <module>
    from console import *
  File "C:\Python26-x86\lib\site-packages\pyreadline\console\console.py", line 6
05, in <module>
    msvcrt = cdll.LoadLibrary(ctypes.util.find_msvcrt())
  File "C:\Python26-x86\Lib\ctypes\__init__.py", line 431, in LoadLibrary
    return self._dlltype(name)
  File "C:\Python26-x86\Lib\ctypes\__init__.py", line 353, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found    
  -- or alternatively --
WindowsError: [Error 1114] A dynamic link library (DLL) initialization routine f
ailed
Run Code Online (Sandbox Code Playgroud)

我知道正在加载的DLL是msvcr90.dll,因为我插入print self._namectypes.py.

应用程序运行我需要的大多数Python脚本,除了那些加载的脚本pyreadline.

这些相同的脚本从安装的Python可执行文件运行没有问题.

这可能是什么原因?

更新2简单也LoadLibrary("msvcr90.dll")失败了.我已经将DLL添加到应用程序清单中,正如'net上的各个地方所建议的那样.这没有用.这是嵌入在可执行文件中的清单:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="amd64" publicKeyToken="1fc8b3b9a1e18e3b" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>
Run Code Online (Sandbox Code Playgroud)

这个清单和嵌入在python.exe中的清单确实匹配,但python.exe可以打开DLL而我的应用程序不能.我很困惑.

Dim*_*ilo 5

更新!
出现问题是因为系统尝试从不同的源加载msvcr90.dll.首先,当应用程序启动时,然后启动python脚本.
要解决这个问题,您确实应该在应用程序中放置正确的清单文件.
我在项目的根目录中使用以下内容创建了一个added.manifest文件:

<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="win32" name="Microsoft.VC90.CRT" version="9.0.21022.8" processorArchitecture="x86" publicKeyToken="1fc8b3b9a1e18e3b" ></assemblyIdentity>
    </dependentAssembly>
  </dependency>
</assembly>
Run Code Online (Sandbox Code Playgroud)

比我在项目属性/清单工具/输入和输出/附加清单文件中设置此文件
您在清单处理器中的错误处理器架构=" amd64 ".
项目在重建后工作正常.