淘先锋技术网

首页 1 2 3 4 5 6 7

在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进行环境迁移避免这些奇奇怪怪的错误……