我的Windows应用程序嵌入了Python2.6(以前我知道,但这正是我们必须使用的)。它可以运行基本的Python命令,但无法执行
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,因为我在print self._name中插入了ctypes.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>这个清单和嵌入在python.exe中的清单是匹配的,但是python.exe可以打开DLL,而我的应用程序不能。我很困惑。
发布于 2013-11-30 21:49:22
更新了!
因为系统试图从不同的源加载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>在项目属性/报表工具/输入和输出/附加报表文件中设置此文件
您在processorArchitecture="amd64".中的清单中有错误
重建后工程运行良好。
发布于 2018-11-08 03:45:43
通过重新安装python2.7,我在Windows 10上为另一个Python应用程序解决了同样的错误。
https://stackoverflow.com/questions/20175129
复制相似问题