日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

c调python_py_initialize:C调Python出错 是初始化错误?

發布時間:2023/12/19 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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出错 是初始化错误?的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。