如何使用python.h

2024-09-28 17:30:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我的程序中包含了Python.h,当我编译程序时,它会显示多个错误,告诉我“无法打开几个库” 错误消息如下

Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 7: Unable to open include file 'patchlevel.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 8: Unable to open include file 'pyconfig.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 9: Unable to open include file 'pymacconfig.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 50: Unable to open include file 'pyport.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 52: Unable to open include file 'pyatomic.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 63: Unable to open include file 'pymath.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 64: Unable to open include file 'pytime.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 65: Unable to open include file 'pymem.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 67: Unable to open include file 'object.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 68: Unable to open include file 'objimpl.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 69: Unable to open include file 'typeslots.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 71: Unable to open include file 'pydebug.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 73: Unable to open include file 'bytearrayobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 74: Unable to open include file 'bytesobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 75: Unable to open include file 'unicodeobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 76: Unable to open include file 'longobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 77: Unable to open include file 'longintrepr.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 78: Unable to open include file 'boolobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 79: Unable to open include file 'floatobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 80: Unable to open include file 'complexobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 81: Unable to open include file 'rangeobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 82: Unable to open include file 'memoryobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 83: Unable to open include file 'tupleobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 84: Unable to open include file 'listobject.h'
Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 85: Unable to open include file 'dictobject.h'
Error E2228 C:\Borland\bcc55\INCLUDE\Python.h 85: Too many error or warning messages
*** 26 errors in Compile ***

我的程序中没有包含任何上述缺失的库

#include<stdio.h>
#include<Python.h>
int main()
{
     Py_SetProgramName(argv[0]);  
     Py_Initialize();
     PyRun_SimpleString("print("hello")");
     Py_Finalize();
     return 0;
}

Tags: topy程序消息include错误erroropen
2条回答

I did not include any of the above mentioned missing libraries in my program

从技术上讲你做到了。通过包含Python.h,可以有效地包含它所包含和依赖的所有头。如果这些都不存在,那么您的代码就无法编译。您可以找到有关如何将CPython正确构建到Introduction Guide中的更多详细信息

错误消息

Error E2209 C:\Borland\bcc55\INCLUDE\Python.h 7: Unable to open include file 'patchlevel.h'

指示错误(无法打开文件)是由第7行中的文件python.h引起的。您可能没有包含所有这些头文件,但是您的python.h可能包含了这些头文件

但是,

  1. 尝试找出这些文件存储在您的计算机上的位置。然后
  2. 了解如何告诉编译器在何处搜索其他包含文件,并提供找到文件的位置。如果不这样做,编译器只会查看某些预先配置的目录,在您的情况下,这些目录是不够的

相关问题 更多 >