PyTorch のインストールは, 公式 (https://pytorch.org/) の手順で行う.
NVIDIA CUDA ツールキット を使うときは, NVIDIA ドライバは別途インストールすることと,CUDA のバージョン選択では「CUDA 同封の PyTorch を選択する」ことを心に留める.
【目次】
先人に感謝.
【サイト内の関連ページ】
UbuntuUbuntu で OS のシステム更新を行うときは, 端末で,次のコマンドを実行する.
sudo apt -y update sudo apt -yV upgrade sudo /sbin/shutdown -r now
Ubuntu での NVIDIA ドライバのインストール: 別ページ »で説明している.
Python のインストールは行わない(Ubuntu のシステム Python を用いる.)
Python, pip のコマンドでの起動のまとめ.
Ubuntu のシステム Python を用いるとき, python, pip は,次のコマンドで起動できる.
Ubuntu での Python 開発環境(JupyterLab, spyder, nteract)のインストール: 別ページ »で説明している.
端末で,次のコマンドを実行する.
sudo apt -y update sudo apt -y install python-is-python3 python3-dev python-dev-is-python3 python3-pip python3-setuptools python3-venv build-essential
Web ブラウザで最新情報を確認ののち,所定のコマンドによりインストールを行う.
PyTorch の URL: https://pytorch.org/
Linux, pip, Python,NVIDIA CUDA ツールキット 11.6 での実行例
但し,Ubuntu の場合は,「pip」を「sudo pip3」に変えて実行.
sudo pip3 install -U torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
端末で,次のコマンドを実行する.
バージョン番号が表示されれば OK.下の図とは違うバージョンが表示されることがある.
python3 -c "import torch; print( torch.__version__ )"
https://pytorch.org/get-started/locally/ に記載のサンプルプログラムを実行してみる
Python プログラムの実行
Ubuntu では, Python プログラムを動かすために, 「python3」コマンドを使う.
Python プログラムを動かすために, python3のコマンドを使う. Python 開発環境(Jupyter Qt Console, Jupyter ノートブック (Jupyter Notebook), Jupyter Lab, Nteract, Spyder, PyCharm, PyScripterなど)も便利である. Python 開発環境の説明: 別ページ »にまとめ
from __future__ import print_function import torch x = torch.rand(5, 3) print(x) exit()
Python プログラムを実行する
import torch torch.cuda.is_available() exit()