致命错误:Python.h:没有这样的文件或目录

新手上路,请多包涵

我正在尝试使用 C 扩展文件构建共享库,但首先我必须使用以下命令生成输出文件:

 gcc -Wall utilsmodule.c -o Utilc

执行命令后,我收到以下错误消息:

 > utilsmodule.c:1:20: fatal error: Python.h: No such file or directory
compilation terminated.

我已经通过互联网尝试了所有建议的解决方案,但问题仍然存在。我对 Python.h 没有任何问题。我设法在我的机器上找到该文件。

原文由 Mohanad Y. 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 812
2 个回答

我设法解决了这个问题并在一个命令中生成了 .so 文件

gcc -shared -o UtilcS.so
-fPIC -I/usr/include/python2.7 -lpython2.7  utilsmodule.c

原文由 Mohanad Y. 发布,翻译遵循 CC BY-SA 3.0 许可协议

看起来你没有正确安装 python dev 的头文件和静态库。使用您的包管理器在系统范围内安装它们。

对于 aptUbuntu、Debian… ):

 sudo apt-get install python-dev   # for python2.x installs
sudo apt-get install python3-dev  # for python3.x installs

对于 yumCentOS、RHEL… ):

 sudo yum install python-devel    # for python2.x installs
sudo yum install python3-devel   # for python3.x installs

对于 dnfFedora… ):

 sudo dnf install python2-devel  # for python2.x installs
sudo dnf install python3-devel  # for python3.x installs

对于 zypperopenSUSE… ):

 sudo zypper in python-devel   # for python2.x installs
sudo zypper in python3-devel  # for python3.x installs

对于 apk高山… ):

 # This is a departure from the normal Alpine naming
# scheme, which uses py2- and py3- prefixes
sudo apk add python2-dev  # for python2.x installs
sudo apk add python3-dev  # for python3.x installs

对于 apt-cygCygwin … ):

 apt-cyg install python-devel   # for python2.x installs
apt-cyg install python3-devel  # for python3.x installs

注意: python3-dev 不会自动覆盖 python3 的所有次要版本,如果您使用的是 python 3.8,您可能需要安装 python3.8-dev。

原文由 wim 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题