简体   繁体   中英

Python.h is in PATH but still not found

I am creating a Python module using C, though when I use #include <Python.h> it says that it find this file, even though I have added it to the user PATH variable.

If I use #include "C:/Users/<my user>/AppData/Local/Programs/Python/Python38/include/Python.h" it works on my PC, though this leads to errors when importing via PyPi, so I would like the first method to work.

Any ideas as to how I can fix this would be greatly appreciated!

I don't know of any compilers that use PATH to find include files. Instead, they use a separate environment variable such as C_INCLUDE_PATH . You need to find the correct environment variable to set.

You can almost certainly set this in CLion's settings somewhere, either globally or for the specific project. Check out their help file: https://www.jetbrains.com/help/clion/managing-included-files.html and https://www.jetbrains.com/help/clion/absolute-path-variables.html

Alternatively, all compilers have a command-line option to specify the include search path. For gcc , use -I .

I found out a way to get around this issue by simply using the preprocessor and CLion specific definitions:

#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

which will use the specific path in CLion and the header when building the python module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM