c调python_py_initialize:C调Python出错 是初始化错误?
還是pythonpath和pythonname變量沒有配置正確?
In an application embedding Python, this should be called before using any other Python/C API functions; with the exception of?Py_SetProgramName(),?Py...
在嵌套Python的應用中,應該在使用任何Python/C API方法之前調用該方法;
C++調Python示例
程序剛開始運行到Py_Initialize()函數,報錯:ImportError:Nomodulenamedsite如遇到這個函數報錯那么基本上就是你沒有將相關路徑添加到環境變量中。兩個方法:一個就是補全python的環境變量。另一個就是手動設置初始化函數的搜尋路徑(也就是加載路徑)環境變量設置方法自己去找網上一堆。手動添加搜尋路徑函數為:Py_SetPythonHome("python的安裝路徑");//如:C:/Python27;只需要到最外層就可以啦
程序剛開始運行到Py_Initialize()函數,報錯:ImportError: No module named site
如遇到這個函數報錯那么基本上就是你沒有將相關路徑添加到環境變量中。
兩個方法:
一個就是補全python的環境變量。
另一個就是手動設置初始化函數的搜尋路徑(也就是加載路徑)
環境變量設置方法自己去找網上一堆。
手動添加搜尋路徑函數為:Py_SetPythonHome("python的安裝路徑");//如:C:/Python27;只需要到最外層就可以啦
以上是關于vs2010調用python中Py_Initialize函數報錯的原因的內容,更多 調用 initialize 函數 原因 Python Vs2010 關于 py 的內容,請您使用右上方搜索功能獲取相關信息。
C++調用Python Py_Initializez中斷:
2017年11月13日 19:58:40 weixin_38105245 閱讀數:1690
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")
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的c调python_py_initialize:C调Python出错 是初始化错误?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 函数可以作为容器对象的元素
- 下一篇: 飞天遁地、装备合成,任天堂《塞尔达传说: