我知道如何在命令行上使用 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/