[python]torch がインストールできない場合の対応策

python_logo

この記事には広告を含む場合があります。

記事内で紹介する商品を購入することで、当サイトに売り上げの一部が還元されることがあります。

Pythonロゴは、Python Software Foundationの商標です。

torch をインストールを実行すると Killed される

python 機械学習ライブラリである torch をインストールするとき

pip install torch

を実行したときに途中でプロセスが Killed されてモジュールがインストールできない状況に遭遇する場合があります。

実行例を示すと下記のような感じ。

jupyter@localhost:~$ pip install torch
Collecting torch
  Downloading torch-1.11.0-cp38-cp38-manylinux1_x86_64.whl (750.6 MB)
     |████████████████████████████████| 750.6 MB 19.7 MB/s eta 0:00:01Killed

インストールが失敗して対処法の模索に時間がかかったため、解決法をメモしておきます。

 

対処法

解決方法は「pip install」のコマンドに対して、「–no-cache-dir」オプションを付与すること。具体的なコマンドで表すと

pip –no-cache-dir install torch

であれば Killed を回避できました。

「–no-cache-dir」はキャッシュを生成しないオプションなのですが、これで回避できる原因は不明。容量不足の可能性も考えましたが、100GB程の空き容量があったので本当に原因が分からず。。。

とりあえず正常動作したので深く考えるのは止めました(苦笑)。

最後に念のためコマンドの実行履歴も残しておきます。

jupyter@localhost:~$ pip --no-cache-dir install torch
Collecting torch
  Downloading torch-1.11.0-cp38-cp38-manylinux1_x86_64.whl (750.6 MB)
     |████████████████████████████████| 750.6 MB 126.3 MB/s 
Collecting typing-extensions
  Downloading typing_extensions-4.2.0-py3-none-any.whl (24 kB)
Installing collected packages: typing-extensions, torch
  WARNING: The scripts convert-caffe2-to-onnx, convert-onnx-to-caffe2 and torchrun are installed in '/home/jupyter/.local/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed torch-1.11.0 typing-extensions-4.2.0

 

 

Linuxの知識については下記の本も参考になるので、スキルアップにお役立てください。

created by Rinker
三宅 英明 (著)、大角 祐介 (著)
ページ数: 440ページ
出版社:SBクリエイティブ
発売日:2015/06/06

出典:amazon