C语言中调用python

您所在的位置:网站首页 c调用python库 C语言中调用python

C语言中调用python

#C语言中调用python| 来源: 网络整理| 查看: 265

C

语言中调用

python

1

(无参数传递)

 

1

Python

简介

 

Python

是一种脚本语言,不需要编译就可以被直接运行,只要编写完程序后修改文件的属

性为可执行,就可被运行。

 

2

C

语言中调用

python

的步骤

 

 

2.1

Ubuntu

下首先要配置下环境(安装

python-dev

,即

python core developer

 

sudo apt-get install python-dev 

 

或者

 

sudo aptitude install python-dev 

 

2.2

:编写

python

文件

 

 

2.3

:编写

C

程序

 

1. 

设置编译环境,其实就是设置

Python

的头文件和库文件目录

 

2. 

初始化

Python

解释器:

 

   

Py_Initialize();

 

3. 

调用

Python

文件中的函数

 

4. 

释放资源

 

   

Py_Finalize(); 

 

2.4

:编译

C

程序

 

gcc -o emc emc.c -I/usr/include/python2.3 -lpython2.3 -L/usr/lib/python2.2/config 

其中:

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3