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

时间:2018-03-02 06:53:36

标签: python c cython

尝试将.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.

1 个答案:

答案 0 :(得分:1)

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

您似乎拥有Linux,因此请检查您是否安装了正确的python*-dev软件包。

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

的输出
pkg-config --cflags python3
pkg-config --libs python3

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

相关问题