python37.dll在可执行文件中未链接

python37.dll not linked in executable

本文关键字:链接 可执行文件 dll python37      更新时间:2023-10-16

我用python扩展了c ++,但可执行文件不会在没有安装python的系统上运行。

#include "C:.....python.h"
int main()
{
Py_Initialize();
PyRun_SimpleString("print("hello world")n")
Py_Finalize();
return 0;
}

当我在未安装 python 的 Windows 系统上运行时,我收到以下错误:

The code execution cannot proceed because python37.dll was not found. Reinstalling the program may fix the problem.

如何将 python37.dll 链接到可执行文件。

确保你的python文件夹在你的PATH中,这样它才能找到有问题的DLL。

从命令行:

c:> set PATH=c:pythonpython37;%PATH%
c:> cd /d c:pathtoyourexe
c:pathtoyouexe> myprogram.exe

有关如何查找和加载 DLL 的更多详细信息,请阅读 MSDN 上的动态链接库搜索顺序页

根据定义,DLL 是一个动态链接的库,它是一个单独的模块,在运行时查找和解析。

如果未安装 Python,则应用程序将无法运行。

您需要将 Python 与您的应用程序捆绑在一起,或者在应用程序安装之前/期间安装 Python。

或者,您可以尝试静态链接 Python,在这种情况下,它将成为可执行文件的一部分,不需要单独安装。