使用cython将.py程序转换为c语言

问题描述 投票:0回答:1

试图将.py代码转换为c语言。 (我拿了样本hello world.py程序)我用下面的编译。

cython --embed -o hello_world.c hello_world.py

现在我必须将其作为可执行文件

gcc -Os -I /usr/include/python3.3m -o hello hello.c -lpython3.3m -lpthread -lm -lutil -ldl

我不明白我如何使用上面的命令和hello.c/root/cythonrnd。如果我运行这个我收到以下错误:

hello.c:8:22: fatal error: pyconfig.h: No such file or directory
#include "pyconfig.h"
^
compilation terminated.
python c cython
1个回答
1
投票

您需要一个系统上不存在的python版本,或者只是您没有安装开发人员文件。

看来你有Linux,所以检查你是否也安装了正确的python*-dev软件包。

通常,您不应该明确地包含路径:使用输出

pkg-config --cflags python3
pkg-config --libs python3

在您的构建脚本中,或在您的gcc命令行中。将python3替换为python用于普通系统Python版本,或指定python版本,例如python3.6

© www.soinside.com 2019 - 2024. All rights reserved.