记录一下服务器上解决ninja报错的过程:
RuntimeError: Ninja is required to load C++ extensions
当代码需要调用torch.utils.cpp_extension.py文件时,如果未能按照ninja库则会报错:
RuntimeError: Ninja is required to load C++ extensions
# 安装ninjia库
pip install ninja
安装之后,发现命令行运行可以执行,但使用pycharm的run/debug仍然报错,故使用which命令查询ninja位置:
$ which ninja
/usr/bin/which: no ninja in (/share/home/gpu2003/local/gcc5/bin:/share/home/gpu2003/miniconda3/bin:/usr/lib64/qt-3.3/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/share/home/gpu2003/.local/bin:/share/home/gpu2003/bin)
$ source activate env
(env)$ which ninja
~/miniconda3/envs/env/bin/ninja
要在对应python环境下才能找到ninja库,故为pycharm添加环境变量:
Your compiler (c++) is not compatible with the compiler Pytorch was built with for this platform, which is g++ on linux.
解决了报错以后出现了警告:
!! WARNING !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (c++) is not compatible with the compiler Pytorch was
built with for this platform, which is g++ on linux. Please
use g++ to to compile your extension. Alternatively, you may
compile PyTorch from source using c++, and then you can also use
c++ to compile your extension.
See https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md for help
with compiling PyTorch from source.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
这是因为服务器默认编译器是c++,而pytorch需要使用g++:
vi ~/.bashrc
export CXX=g++
source ~/.bashrc
Your compiler (g++ 4.8.5) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 5.0 and above.
出现了新的报错:
!! WARNING !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (g++ 4.8.5) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 5.0 and above.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html.
See https://gist.github.com/goldsborough/d466f43e8ffc948ff92de7486c5216d6
for instructions on how to install GCC 5 or higher.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
但是g++版本高于5.0.0:
$ g++ --version
g++ (GCC) 5.2.0
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
因服务器文件无sudo权限,暂时还未解决。