【编译Debug】xxx/torch/csrc/python_headers.h:10:10: fatal error: Python.h: No such file or directory

在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.

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

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

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

再进行编译即可成功。

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值