请问,确定 numpy include 在目标系统上的正确路径的最简单/最优雅的方法是什么?然后通过 make 命令使用它?目前我正在使用
gcc ... -I/usr/include/python2.7/-I/usr/lib/python2.7/site-packages/numpy/core/include/numpy/
我希望根据执行构建的系统自动选择这两个包含。
看来我可以像这样获得第二个包含:
python -c "import numpy; print numpy.__path__[0] + 'core/include/numpy/'"
但我不确定第一个,即使我仍然不确定如何从 makefile 中最好地使用它(以一种简单/优雅的方式)
最佳答案
numpy.get_include()
是获取包含的最简单/最好的方法。如果你的 C 扩展模块使用 numpy 那么在 Extension你必须使用 include_dirs=[numpy.get_include()]
。为什么 numpy.get_include()
好像没有我不知道的文档。
然后您可以按照 user1056255 的建议进行操作,但会好一点...
CFLAGS = $(shell python-config --includes) $(shell python -c "import numpy; print '-I' + numpy.get_include()")
关于python - 使用 numpy 扩展的 C 程序的 Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9019580/