python - 将 python 脚本编译为 C 时如何修复 Cython header 错误

标签 python c cython cythonize

我知道如何在命令行上使用 cython 时将 Python 解释器嵌入到我的 script.c 脚本中 SO post .

但是,不幸的是,我在 .c 文件的 header 中遇到以下错误。

/* Generated by Cython 0.29.6 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#ifndef Py_PYTHON_H
    #error Python headers needed to compile C extensions, please install development version of Python.
#elif PY_VERSION_HEX < 0x02060000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000)
    #error Cython requires Python 2.6+ or Python 3.3+.
#else

由于我使用的是 MacOS,因此我通过自制程序安装了 python,因此我也知道我的 header 位于以下目录中。

/usr/local/Cellar/python3/3.7.0/Frameworks/Python.framework/Versions/3.7/Headers

了解了 Python header 所在的位置后,如何修复使用 cython 以 C 代码编译 Python 代码时出现的错误,使其成为可移植的可执行文件?

最佳答案

你安装了 python 开发吗?
Linux:

sudo apt-get install python python-dev python-all python-all-dev

编辑:抱歉,没看到 Mac。尽管brew也有头文件,但您可能需要python-devel:

brew reinstall python

关于python - 将 python 脚本编译为 C 时如何修复 Cython header 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55527377/

相关文章:

python - cython 中 str 和 Py_UNICODE 的驻留和内存地址

python - theano 打印 pydotprint - 运行时错误 : failed to import pydot

python - C.dll 如何向 Python 公开变量?

c - 使用 execvp 连接标准输入吗?

c - K&R 中的类型转换

python - Cython 具体化属性?

python - 加速 Python 中的数学计算

python,如何知道一年中的周数,周六为一周的第一天

python - 检查数字是否为斐波那契数的函数?

C regexec 段错误