我正在使用C创建一个Python模块,尽管当我使用#include <Python.h>
时它说它找到了该文件,即使我已将其添加到用户PATH
变量中。
如果我使用#include "C:/Users/<my user>/AppData/Local/Programs/Python/Python38/include/Python.h"
,它可以在我的PC上运行,尽管在通过PyPi导入时会导致错误,所以我希望第一种方法可以工作。
任何有关如何解决此问题的想法将不胜感激!
答案 0 :(得分:2)
我不知道任何使用In [1]: tup = [('apple fruit', 91), ('the fruit is an apple', 34), ('banana apple', 78), ('guava tree', 11), ('delicious apple', 88)]
In [2]: input_string = 'fruit apple'
In [3]: input_string_set = set(input_string.split(' '))
In [4]: input_string_set
Out[4]: {'apple', 'fruit'}
In [10]: [t for t in tup if input_string_set.issubset(set(t[0].split(' ')))]
Out[10]: [('apple fruit', 91), ('the fruit is an apple', 34)]
In [11]:
来查找包含文件的编译器。而是使用单独的环境变量,例如PATH
。您需要找到要设置的正确环境变量。
几乎可以肯定,可以在CLion的设置中对此进行设置,无论是全局设置还是特定项目的设置。查看他们的帮助文件:https://www.jetbrains.com/help/clion/managing-included-files.html和https://www.jetbrains.com/help/clion/absolute-path-variables.html
或者,所有编译器都有一个命令行选项来指定包含搜索路径。对于C_INCLUDE_PATH
,请使用gcc
。
答案 1 :(得分:0)
我找到了一种方法,只需使用预处理器和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中的特定路径和标头。