还是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")

py_initialize:C调Python出错 是初始化错误?的更多相关文章

  1. Python程序的常见错误(收集篇)

    关于Python Python是一门解释性的,面向对象的,并具有动态语义的高级编程语言.它高级的内置数据结构,结合其动态类型和动态绑定的特性,使得它在快速应用程序开发(Rapid Applicatio ...

  2. C++调Python示例(转载)

    C++调Python,代码粘贴如下: #include <iostream> #include <Python.h> using namespace std; void Hel ...

  3. python学习笔记014——错误和异常

    Python有两种错误很容易辨认:语法错误和异常. 1 什么是语法错误 Python 的语法错误或者称之为解析错,是初学者经常碰到的,如下实例 if i>4 print("if语句输出 ...

  4. Python 新手常犯错误

    Python 新手常犯错误(第二部分) 转发自:http://blog.jobbole.com/43826/ 作用域 在这篇文章里,我们来关注作用域在Python被误用的地方.通常,当我们定义了一个全 ...

  5. python中常见的错误

    python中常见的错误   1.IndentationError: unindent does not match any outer indentation leve 众所周知,Python语法要 ...

  6. Python:no encoding declared 错误

    使用Python编译的时候出现如下错误: SyntaxError: Non-ASCII character ‘\xe5’ in file magentonotes.com.py on line 2, ...

  7. Python学习笔记七-错误和异常

    程序员总是和各种错误打交道,学习如何识别并正确的处理程序错误是很有必要的. 7.1错误和异常 1.错误 从软件方面来看,错误分为语法错误和逻辑错误两种.这两种错误都将导致程序无法正常进行下去,当Pyt ...

  8. Python更新pip出现错误解决方法

    Python更新pip出现错误解决方法 更新pip python -m pip install --upgrade pip 查看时报错 解决方法 在命令栏(即win+r)输入:easy_install ...

  9. Python学习 Part6:错误和异常

    Python学习 Part6:错误和异常 两种不同类型的错误:语法错误和异常 1. 语法错误 语法错误,也被称作解析错误: >>> while True print('Hello w ...

随机推荐

  1. bzoj 2259 [Oibh]新型计算机 ——最短路(建图)

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2259 不是 n^2 条边!连那条边权为0的边之后,只要每个位置向它的前一个位置和后一个位置连 ...

  2. 利用bat合并两个hex文件

    单片机程序如果有IAP功能的话,就会生成两个hex文件,一个是Boot,一个是App,如果给让生产烧录两个文件,就会降低生产效率,所以在烧录前最好将两个文件合并成一个文件,烧录一次即可,合并方法如下: ...

  3. git fatal: remote origin already exists. 报错解决

    在研究git的时候,随便输了个 git remote add origin xxx; 然后再真正add 远程仓库的时候,报了git fatal: remote origin already exist ...

  4. Idea 如何设置微软雅黑等其它字体

    使用过idea的同学都知道,idea的功能相对于explise来说,功能太强大了啊~个人感觉,idea真心挺智能的.但是,这里有一个小瑕疵,就是能够设置的字体,有限! 对于用惯了 微软雅黑 字体的人, ...

  5. TCP与UDP比较 以及并发编程基础知识

    一.tcp比udp真正可靠地原因 1.为什么tcp比udp传输可靠地原因: 我们知道在传输数据的时候,数据是先存在操作系统的缓存中,然后发送给客户端,在客户端也是要经过客户端的操作系统的,因为这个过程 ...

  6. java成神之——MySQL Connector/J 的基本使用

    使用示例 DBCP连接池 结语 使用示例 public class demo { static Connection con = null; static Statement st = null; s ...

  7. 用cascade删除有约束的表或记录

    删除有约束的表 Drop table TERMPRO_RULE_ROUTE_TYPE cascade constraints:

  8. 第十三章 MySQL用户管理(待续)

    ·············

  9. delphi 天气预报

    天气预报 var astream : tmemorystream; sStream : TStringStream; jv : TJSONValue; begin astream := tmemory ...

  10. C语言运算符优先级和口诀 (转)

    一共有十五个优先级: 1   ()  []  .  -> 2   !  ~   -(负号) ++  --   &(取变量地址)*   (type)(强制类型)    sizeof 3   ...