我的github
posts - 3243,  comments - 42,  views - 158万

还是pythonpath和pythonname变量没有配置正确?

 

py_initialize()方法是什么?

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示例

https://www.cnblogs.com/Hisin/archive/2012/02/27/2370590.html

 

程序刚开始运行到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")
posted on   XiaoNiuFeiTian  阅读(7738)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2016-12-12 小强 ROS 机器人教程
2016-12-12 图像识别
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示