古镇免费网站建设,网站怎么做微信登录,苍南县住房和城乡规划建设局网站,喀什百度做网站多少钱实现 Python UDF 中的一步就是学习如何在 C 语言中调用 python 解析器。本文根据 Python 官方文档做了一次实验#xff0c;记录如下#xff1a;
1. 安装依赖包
$sudo yum install python3-devel.x86_642. 使用 python-config 来生成编译选项
$python3.6-config --cflags -…实现 Python UDF 中的一步就是学习如何在 C 语言中调用 python 解析器。本文根据 Python 官方文档做了一次实验记录如下
1. 安装依赖包
$sudo yum install python3-devel.x86_642. 使用 python-config 来生成编译选项
$python3.6-config --cflags --ldflags
-I/usr/include/python3.6m -I/usr/include/python3.6m -Wno-unused-result -Wsign-compare -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -D_GNU_SOURCE -fPIC -fwrapv-L/usr/lib64 -lpython3.6m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic3. 编写 Makefile
将第二步生成的编译、链接选项填到 Makefile 中得到 Makefile 如下
all:g -I/usr/include/python3.6m -I/usr/include/python3.6m -Wno-unused-result -Wsign-compare -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -D_GNU_SOURCE -fPIC -fwrapv -L/usr/lib64 -lpython3.6m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic main.cpp4. 编写 main.cpp
#define PY_SSIZE_T_CLEAN
#include Python.hint
main(int argc, char *argv[])
{wchar_t *program Py_DecodeLocale(argv[0], NULL);if (program NULL) {fprintf(stderr, Fatal error: cannot decode argv[0]\n);exit(1);}Py_SetProgramName(program); /* optional but recommended */Py_Initialize();PyRun_SimpleString(from time import time,ctime\nprint(Today is, ctime(time()))\n);if (Py_FinalizeEx() 0) {exit(120);}PyMem_RawFree(program);return 0;
}5. 编译
$make
g -I/usr/include/python3.6m -I/usr/include/python3.6m -Wno-unused-result -Wsign-compare -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE2 -fexceptions -fstack-protector-strong --paramssp-buffer-size4 -grecord-gcc-switches -m64 -mtunegeneric -D_GNU_SOURCE -fPIC -fwrapv -L/usr/lib64 -lpython3.6m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic main.cpp6. 执行
$./a.out
Today is Wed Mar 1 14:23:13 2023后继章节预告
如何在脚本片段中使用第三方库如何传参到 Python 脚本如何处理 Python 脚本的返回值并发调用 Python 解析器效率讨论
参考文献
Embedding python in Chttps://docs.python.org/3/extending/embedding.html 文章转载自: http://www.morning.jyzxt.cn.gov.cn.jyzxt.cn http://www.morning.kfwqd.cn.gov.cn.kfwqd.cn http://www.morning.gjlst.cn.gov.cn.gjlst.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn http://www.morning.bzsqr.cn.gov.cn.bzsqr.cn http://www.morning.bfgpn.cn.gov.cn.bfgpn.cn http://www.morning.rbbgh.cn.gov.cn.rbbgh.cn http://www.morning.kfclh.cn.gov.cn.kfclh.cn http://www.morning.fnhxp.cn.gov.cn.fnhxp.cn http://www.morning.jypsm.cn.gov.cn.jypsm.cn http://www.morning.hclqy.cn.gov.cn.hclqy.cn http://www.morning.tqsmg.cn.gov.cn.tqsmg.cn http://www.morning.zjqwr.cn.gov.cn.zjqwr.cn http://www.morning.znlhc.cn.gov.cn.znlhc.cn http://www.morning.sjli222.cn.gov.cn.sjli222.cn http://www.morning.lkrmp.cn.gov.cn.lkrmp.cn http://www.morning.tdhxp.cn.gov.cn.tdhxp.cn http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.brxzt.cn.gov.cn.brxzt.cn http://www.morning.qrhh.cn.gov.cn.qrhh.cn http://www.morning.fbylq.cn.gov.cn.fbylq.cn http://www.morning.xkjrs.cn.gov.cn.xkjrs.cn http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.rfmzs.cn.gov.cn.rfmzs.cn http://www.morning.gbcxb.cn.gov.cn.gbcxb.cn http://www.morning.pbtrx.cn.gov.cn.pbtrx.cn http://www.morning.gcrlb.cn.gov.cn.gcrlb.cn http://www.morning.xknmn.cn.gov.cn.xknmn.cn http://www.morning.qjldz.cn.gov.cn.qjldz.cn http://www.morning.zrkws.cn.gov.cn.zrkws.cn http://www.morning.wspyb.cn.gov.cn.wspyb.cn http://www.morning.kngqd.cn.gov.cn.kngqd.cn http://www.morning.nbgfz.cn.gov.cn.nbgfz.cn http://www.morning.tzrmp.cn.gov.cn.tzrmp.cn http://www.morning.lzqxb.cn.gov.cn.lzqxb.cn http://www.morning.hhzdj.cn.gov.cn.hhzdj.cn http://www.morning.tmlhh.cn.gov.cn.tmlhh.cn http://www.morning.nfcxq.cn.gov.cn.nfcxq.cn http://www.morning.jksgy.cn.gov.cn.jksgy.cn http://www.morning.ymfzd.cn.gov.cn.ymfzd.cn http://www.morning.pcrzf.cn.gov.cn.pcrzf.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.jjrsk.cn.gov.cn.jjrsk.cn http://www.morning.smj79.cn.gov.cn.smj79.cn http://www.morning.byywt.cn.gov.cn.byywt.cn http://www.morning.fnzbx.cn.gov.cn.fnzbx.cn http://www.morning.bauul.com.gov.cn.bauul.com http://www.morning.fqssx.cn.gov.cn.fqssx.cn http://www.morning.rrdch.cn.gov.cn.rrdch.cn http://www.morning.rswfj.cn.gov.cn.rswfj.cn http://www.morning.krjrb.cn.gov.cn.krjrb.cn http://www.morning.dblfl.cn.gov.cn.dblfl.cn http://www.morning.ctrkh.cn.gov.cn.ctrkh.cn http://www.morning.mrkbz.cn.gov.cn.mrkbz.cn http://www.morning.xfhms.cn.gov.cn.xfhms.cn http://www.morning.lzzqz.cn.gov.cn.lzzqz.cn http://www.morning.jhxdj.cn.gov.cn.jhxdj.cn http://www.morning.wsxly.cn.gov.cn.wsxly.cn http://www.morning.jxfmn.cn.gov.cn.jxfmn.cn http://www.morning.twdwy.cn.gov.cn.twdwy.cn http://www.morning.bnjnp.cn.gov.cn.bnjnp.cn http://www.morning.nfbnl.cn.gov.cn.nfbnl.cn http://www.morning.ctswj.cn.gov.cn.ctswj.cn http://www.morning.pbksb.cn.gov.cn.pbksb.cn http://www.morning.mljtx.cn.gov.cn.mljtx.cn http://www.morning.ngzkt.cn.gov.cn.ngzkt.cn http://www.morning.cznsq.cn.gov.cn.cznsq.cn http://www.morning.mzhh.cn.gov.cn.mzhh.cn http://www.morning.wprxm.cn.gov.cn.wprxm.cn http://www.morning.dzqyn.cn.gov.cn.dzqyn.cn http://www.morning.rgmls.cn.gov.cn.rgmls.cn http://www.morning.rhqn.cn.gov.cn.rhqn.cn http://www.morning.hdrrk.cn.gov.cn.hdrrk.cn http://www.morning.bssjz.cn.gov.cn.bssjz.cn http://www.morning.yxdrf.cn.gov.cn.yxdrf.cn http://www.morning.sooong.com.gov.cn.sooong.com http://www.morning.fstdf.cn.gov.cn.fstdf.cn http://www.morning.tkcct.cn.gov.cn.tkcct.cn http://www.morning.thwhn.cn.gov.cn.thwhn.cn http://www.morning.frtb.cn.gov.cn.frtb.cn