当前位置:   article > 正文

【编译Debug】xxx/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory_编译报错torch/include/torch/csrc/python_headers.h:11:2

编译报错torch/include/torch/csrc/python_headers.h:11:20: 致命错误: python.h:

在python工程进行c++扩展的编译时(使用诸如 python setup.py install 之类的命令)最近发现这样的报错:

FAILED: /data1/***/code/TransDETR/models/ops/build/temp.linux-x86_64-cpython-310/data1/***/code/TransDETR/models/ops/src/vision.o
c++ -MMD -MF /data1/***code/TransDETR/models/ops/build/temp.linux-x86_64-cpython-310/data1/***/code/TransDETR/models/ops/src/vision.o.d -pthread -B /home/dell/miniconda3/envs/transDETR/compiler_compat -Wno-unused-result -Wsign-compare -DNDEBUG -fwrapv -O2 -Wall -fPIC -O2 -isystem /home/dell/miniconda3/envs/transDETR/include -fPIC -O2 -isystem /home/dell/miniconda3/envs/transDETR/include -fPIC -DWITH_CUDA -I/data1/***/code/TransDETR/models/ops/src -I/data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include -I/data1/***anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/torch/csrc/api/include -I/data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/TH -I/data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/THC -I/usr/local/cuda-10.2/include -I/home/dell/miniconda3/envs/transDETR/include/python3.10 -c -c /data1/***/code/TransDETR/models/ops/src/vision.cpp -o /data1/***/code/TransDETR/models/ops/build/temp.linux-x86_64-cpython-310/data1/***/code/TransDETR/models/ops/src/vision.o -DTORCH_API_INCLUDE_EXTENSION_H '-DPYBIND11_COMPILER_TYPE="_gcc"' '-DPYBIND11_STDLIB="_libstdcpp"' '-DPYBIND11_BUILD_ABI="_cxxabi1011"' -DTORCH_EXTENSION_NAME=MultiScaleDeformableAttention -D_GLIBCXX_USE_CXX11_ABI=0 -std=c++14
In file included from /data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/torch/csrc/Device.h:3:0,
                 from /data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/torch/csrc/api/include/torch/python.h:8,
                 from /data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/torch/extension.h:6,
                 from /data1/***/code/TransDETR/models/ops/src/cpu/ms_deform_attn_cpu.h:12,
                 from /data1/***/code/TransDETR/models/ops/src/ms_deform_attn.h:13,
                 from /data1/***/code/TransDETR/models/ops/src/vision.cpp:11:
/data1/***/anaconda3/envs/transDETR/lib/python3.10/site-packages/torch/include/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory
 #include <Python.h>
          ^~~~~~~~~~
compilation terminated.

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

查了很多资料都说是没有装python-dev之类的包,但是在检查环境的时候发现都是具备的。

这时候就需要加入一个有Python.h的路径帮助C++编译器找到这个文件。我这里在/usr/include/python3.6m/

export CPATH=$CPATH:/usr/include/python3.6m/
  • 1

再进行编译即可成功。

ps: 原因可能是我直接copy另一台服务器上的虚拟环境导致路径对不上,以后尽量还是要使用conda pack进行环境迁移避免这些奇奇怪怪的错误……

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/81877
推荐阅读
相关标签
  

闽ICP备14008679号