gpt4 book ai didi

python - 使用cython将.py程序转换为C语言

转载 作者:行者123 更新时间:2023-11-30 14:50:20 24 4
gpt4 key购买 nike

尝试将 .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 版本在您的系统上不存在,或者只是您没有安装开发人员文件。

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

一般来说,您不应该显式包含路径:使用

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

在你的构建脚本中,或者在你的 gcc 命令行中。将 python3 替换为 python 作为正常系统 Python 版本,或者指定一个 python 版本,例如python3.6.

关于python - 使用cython将.py程序转换为C语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49064120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com