社区
脚本语言
帖子详情
如何在VC项目中嵌入python?
uaiia
2004-03-18 04:25:37
拿到一个免费的共享代码,里面全是python文件,现在需要在vc中嵌入python的功能,不知如何实现?
...全文
514
14
打赏
收藏
如何在VC项目中嵌入python?
拿到一个免费的共享代码,里面全是python文件,现在需要在vc中嵌入python的功能,不知如何实现?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
14 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
oncsdn
2004-08-17
打赏
举报
回复
有点误,如下
#ifdef _DEBUG
#define D_E_B_U_G
#undef _DEBUG
#include <Python.h>
#else
#include <Python.h>
#endif
#ifdef D_E_B_U_G
#define _DEBUG
#undef D_E_B_U_G
#endif
oncsdn
2004-08-17
打赏
举报
回复
关于 lib 问题
1. 在VC中加入 C:\Python23\Lib 路径
2. 按如入方式头文件
#ifdef _DEBUG
#define D_E_B_U_G
#undef _DEBUG
#include <Python.h>
#endif
#ifdef D_E_B_U_G
#define _DEBUG
#undef D_E_B_U_G
#endif
参阅: http://community.csdn.net/Expert/topic/3037/3037303.xml?temp=.7859918
oncsdn
2004-08-17
打赏
举报
回复
好东西呀
还是 CSDN 好,俺在 google 上找了半天也没有找到
mark....................................
albertlee
2004-08-13
打赏
举报
回复
晕那 ,,,,,
原来是我自己写的东西, 还要mark , 看来我离开 CSDN 论坛的日子是长了点
albertlee
2004-08-13
打赏
举报
回复
我也来 mark 一个
功名半纸
2004-07-04
打赏
举报
回复
mark!!!!!!!!!!!!!!!!!!!
lodestar51
2004-06-26
打赏
举报
回复
学习........
howler
2004-06-18
打赏
举报
回复
mark
zzj0820
2004-06-11
打赏
举报
回复
mark
孙亖
2004-05-07
打赏
举报
回复
mark
albertlee
2004-04-01
打赏
举报
回复
1. 安装 Python 到 d:\python23
2. 新建一个VC项目, 在 Project Setting 中,把 d:\python\include 加入“其他头文件”哪一项,把 d:\python\libs 加入 link 的附加目录里。
3. 在主文件里这样写:
#include <python.h> // PYthon 头文件
#include <stdio.h>
void main(void)
{
Py_Initialize(); //python 解释器的初始化
if(!Py_IsInitialized())
{
printf("can't init python");
return;
}
PyRun_SimpleString("import sys");
PyRun_SimpleString("sys.path.append('./')");
PyObject *pName,*pModule,*pDict,*pFunc,*pArgs,*pRes;
pName = PyString_FromString("pytest"); // 这个就是你要嵌入的python 文件名
pModule = PyImport_Import(pName);
if(!pModule)
{
printf("can't find pytest.py");
getchar();
return ;
}
pDict = PyModule_GetDict(pModule); // 得到python模块中的函数表
if(!pDict)
return;
pFunc = PyDict_GetItemString(pDict,"add");
if(!pFunc || !PyCallable_Check(pFunc))
{
printf("can't find function [add]");
getchar();
return;
}
*pArgs;
// 添参数
pArgs = PyTuple_New(2);
PyTuple_SetItem(pArgs,0,Py_BuildValue("l",343));
PyTuple_SetItem(pArgs,1,Py_BuildValue("l",42356));
PyObject_CallObject(pFunc , pArgs); // 调用 python 程序
pFunc = PyDict_GetItemString(pDict,"str_find");
if(!pFunc || !PyCallable_Check(pFunc))
{
printf("can't find function [add]");
getchar();
return;
}
// 另外一个函数例子,演示了如何向 python 传递参数,和如何传回 C++
pArgs = PyTuple_New(2);
PyTuple_SetItem(pArgs,0,Py_BuildValue("s","abcdef"));
PyTuple_SetItem(pArgs,1,Py_BuildValue("s","de"));
long ret_val = PyInt_AsLong(PyObject_CallObject(pFunc , pArgs));
printf("%d\n",ret_val);
Py_DECREF(pModule);
Py_Finalize(); // 清除
getchar();
}
// -----------------------------------------
python 文件 pytest.py
def add(a,b):
print "in python function add"
print a+b
return
def str_find(str1,str2):
print "str1:",str1
print "str2:",str2
return str1.rfind(str2)
lodestar521
2004-04-01
打赏
举报
回复
学习。。。。。。。。。。。
xrenwu
2004-03-31
打赏
举报
回复
关注
iBear
2004-03-19
打赏
举报
回复
boost http://boost.sourceforge.net/
swig http://swig.sourceforge.net/
Python
嵌入
VC
项目
中
将
python
库
嵌入
vc
项目
中
,支持C++调用
python
脚本,很大程度上简化开发
VC
项目
调用
Python
文件脚本
VC
项目
调用
Python
文件脚本,支持脚本导入其他模块,该工程用
Python
脚本进行IO操作,创建文件以及写数据,解决不需要安装
python
环境就能使用
python
脚本带来的便利
Python
3.1
嵌入
VC
的两个库文件
python
3.1
嵌入
VC
时,在debug环境下编译会提示缺少
python
31_d.lib和
python
31_d.dll,这两个文件在网上是找不到的。我自己编译了一份与大家共享 配制方法大家上网上查吧,这里不方便写出来。享受混合编程的快乐吧
Python
嵌入
C/C++进行开发详解
如果你想把
Python
嵌入
C/C++
中
是比较简单的事情,你需要的是在
VC
中
添加
Python
的include文件目录和lib文件目录。下面我们来看下如何把
Python
嵌入
C/C++
中
。
VC
6.0下,打开 tools->options->directories->show ...
python
_27的调试库(包括lib和dll)
用于在
VC
6/2005下调试
python
的扩展和
嵌入
的库。
python
自身没有带调试的库。 自己找了半天没有找到,生成了一套,就在这里共享。
脚本语言
37,719
社区成员
34,238
社区内容
发帖
与我相关
我的任务
脚本语言
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
复制链接
扫一扫
分享
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
试试用AI创作助手写篇文章吧
+ 用AI写文章