我的Windows应用程序嵌入了Python 2.6(旧的我知道,但这就是我们必须使用的)。它可以运行基本的Python命令但尝试执行失败Python无法打开msvcr90.dll
import ctypes
ctypes.WinDLL("msvcr90.dll")
我收到错误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;
}
与时任V9或V10编译工具链,在x86和AMD64架构,就会失败。
回溯如下:
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
我知道,那是正在加载的DLL是MSVCR90.DLL,因为我已经在ctypes.py
插入print self._name
。
除了加载pyreadline
的应用程序之外,该应用程序还运行我需要的大多数Python脚本。
这些相同的脚本从已安装的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>
此清单和清单嵌入python.exe匹配,但python.exe可以打开DLL和我的应用程序不能。我很困惑。
什么版本的C/C++是你的Windows应用程序构建的? – martineau
@martineau vs2010(toolchain v10.0,msvcr100.dll) –
我认为这可能是你的问题的原因 - 你有效地试图创建一个程序,同时使用两个不同的C/C++运行时库。不速之客,我能想到的那个Python版本的唯一解决方案就是尝试使用VS2010自行重建它。 – martineau