Python.h 在 PATH 中但仍未找到

Python.h is in PATH but still not found

我正在使用 C 创建一个 Python 模块,尽管当我使用 #include <Python.h> 它说它找到了这个文件,即使我已经将它添加到用户 PATH 变量.

如果我使用 #include "C:/Users/<my user>/AppData/Local/Programs/Python/Python38/include/Python.h" 它可以在我的 PC 上运行,尽管这会导致在通过 PyPi 导入时出错,所以我希望第一种方法有效。

任何有关如何解决此问题的想法都将不胜感激!

我找到了一种通过简单地使用预处理器和 CLion 特定定义来解决这个问题的方法:

#ifdef __CLION_IDE_
#include "C:/Users/<user>/AppData/Local/Programs/Python/Python38/include/Python.h"
#include "C:/Users/<user>/AppData/Local/Programs/Python/Python38/include/structmember.h"
#else
#include <Python.h>
#include <structmember.h>
#endif

构建 python 模块时将使用 CLion 中的特定路径和 header。

我不知道有任何编译器使用 PATH 来查找包含文件。相反,他们使用单独的环境变量,例如 C_INCLUDE_PATH。您需要找到正确的环境变量来设置。

您几乎可以肯定地在 CLion 的设置中的某处进行设置,无论是全局设置还是针对特定项目。查看他们的帮助文件:https://www.jetbrains.com/help/clion/managing-included-files.html and https://www.jetbrains.com/help/clion/absolute-path-variables.html

或者,所有编译器都有一个 command-line 选项来指定包含搜索路径。对于 gcc,使用 -I.