C++调用Python Py_Initializez中断

C++中调用Python代码,但是在Py_Initialize函数调用时就中断了,程序是64位的 python是3.5.3的64位版本 
简单的调用代码如下:
#include "stdafx.h"
#include "Python.h"

int _tmain(int argc, _TCHAR* argv[])
{
Py_Initialize();
Py_Finalize();
return 0;
}
运行结果:
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\advapi32.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sechost.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\sspicli.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\cryptbase.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shell32.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\shlwapi.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.4940_none_50916076bcb9a742\msvcr90.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\imm32.dll'. Cannot find or open the PDB file.
'TestEmbedPython.exe' (Win32): Loaded 'C:\Windows\SysWOW64\msctf.dll'. Cannot find or open the PDB file.
The program '[43084] TestEmbedPython.exe' has exited with code 1 (0x1).

没有任何错误提示  运行到Py_Initialize 程序直接崩溃

----------------------------------------------------------------------------------------------

搞了一天终于搞明白,解决方案是在Py_Initialize函数前加一行Py_SetPythonHome(L"D:\\Python35")

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值