RuntimeError: C++ 拡張機能をロードするには Ninja が必要です

サーバー上の ninja エラーを解決するプロセスを記録します。

RuntimeError: C++ 拡張機能をロードするには Ninja が必要です

コードが torch.utils.cpp_extension.py ファイルを呼び出す必要がある場合、忍者ライブラリに従っていない場合、エラーが報告されます。

RuntimeError: Ninja is required to load C++ extensions
# 安装ninjia库
pip install ninja

インストール後、コマンドラインは実行できることがわかりましたが、pycharm の実行/デバッグでは依然としてエラーが報告されるため、what コマンドを使用して 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

ninja ライブラリは、対応する Python 環境でのみ見つかるため、pycharm の環境変数を追加します。

コンパイラ (c++) は、Pytorch がこのプラットフォーム用に構築されたコンパイラ (Linux 上の g++) と互換性がありません。

エラーを解決すると、次の警告が表示されました。

                               !! 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

あなたのコンパイラ (g++ 4.8.5) は PyTorch と ABI 互換性がない可能性があります。
GCC 5.0 以降と ABI 互換のコンパイラを使用してください。

新しいエラーが発生しました:

                               !! 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 権限がないため、問題はまだ解決されていません。

おすすめ

転載: blog.csdn.net/RRRUAAA/article/details/131171809