一,pytorch官网:
https://pytorch.org/
如图:
根据自己的需求选择版本、平台、语言环境等信息,
然后运行命令
二,运行pip安装命令:
[root@img bin]# pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu Looking in indexes: https://download.pytorch.org/whl/cpu Collecting torch Downloading https://download.pytorch.org/whl/cpu/torch-2.0.1%2Bcpu-cp39-cp39-linux_x86_64.whl (195.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 195.4/195.4 MB 2.7 MB/s eta 0:00:00 Collecting torchvision Downloading https://download.pytorch.org/whl/cpu/torchvision-0.15.2%2Bcpu-cp39-cp39-linux_x86_64.whl (1.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.5/1.5 MB 4.2 MB/s eta 0:00:00 Collecting torchaudio Downloading https://download.pytorch.org/whl/cpu/torchaudio-2.0.2%2Bcpu-cp39-cp39-linux_x86_64.whl (4.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 MB 3.3 MB/s eta 0:00:00 Collecting filelock (from torch) Downloading https://download.pytorch.org/whl/filelock-3.9.0-py3-none-any.whl (9.7 kB) Collecting typing-extensions (from torch) Downloading https://download.pytorch.org/whl/typing_extensions-4.4.0-py3-none-any.whl (26 kB) Collecting sympy (from torch) Downloading https://download.pytorch.org/whl/sympy-1.11.1-py3-none-any.whl (6.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 6.5/6.5 MB 2.7 MB/s eta 0:00:00 Collecting networkx (from torch) Downloading https://download.pytorch.org/whl/networkx-3.0-py3-none-any.whl (2.0 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.0/2.0 MB 1.5 MB/s eta 0:00:00 Requirement already satisfied: jinja2 in /usr/local/lib/python3.9/site-packages (from torch) (3.1.2) Collecting numpy (from torchvision) Downloading https://download.pytorch.org/whl/numpy-1.24.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 17.3/17.3 MB 2.7 MB/s eta 0:00:00 Requirement already satisfied: requests in /usr/local/lib/python3.9/site-packages (from torchvision) (2.28.2) Collecting pillow!=8.3.*,>=5.3.0 (from torchvision) Downloading https://download.pytorch.org/whl/Pillow-9.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.2/3.2 MB 1.9 MB/s eta 0:00:00 Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib64/python3.9/site-packages (from jinja2->torch) (2.1.2) Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib64/python3.9/site-packages (from requests->torchvision) (3.1.0) Requirement already satisfied: idna<4,>=2.5 in /usr/lib/python3.9/site-packages (from requests->torchvision) (2.10) Requirement already satisfied: urllib3<1.27,>=1.21.1 in /usr/lib/python3.9/site-packages (from requests->torchvision) (1.26.5) Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.9/site-packages (from requests->torchvision) (2022.12.7) Collecting mpmath>=0.19 (from sympy->torch) Downloading https://download.pytorch.org/whl/mpmath-1.2.1-py3-none-any.whl (532 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 532.6/532.6 kB 1.1 MB/s eta 0:00:00 Installing collected packages: mpmath, typing-extensions, sympy, pillow, numpy, networkx, filelock, torch, torchvision, torchaudio WARNING: The script isympy is installed in '/usr/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. WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in '/usr/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. WARNING: The scripts convert-caffe2-to-onnx, convert-onnx-to-caffe2 and torchrun are installed in '/usr/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 filelock-3.9.0 mpmath-1.2.1 networkx-3.0 numpy-1.24.1 pillow-9.3.0 sympy-1.11.1 torch-2.0.1+cpu torchaudio-2.0.2+cpu torchvision-0.15.2+cpu typing-extensions-4.4.0 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
三,安装完成后查看torch的版本:
[liuhongdi@img ~]$ python3 Python 3.9.16 (main, May 29 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch; >>> torch.__version__ '2.0.1+cpu’
说明:刘宏缔的架构森林—专注it技术的博客,
网址:https://imgtouch.com
本文: https://blog.imgtouch.com/index.php/2023/08/03/rocky-linux-an-zhuang-pytorch-pytorch-2-1-python-3-9-16/
代码: https://github.com/liuhongdi/ 或 https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
四,查看python和pip的版本:
[liuhongdi@img ~]$ python --version Python 3.9.16 [liuhongdi@img ~]$ pip --version pip 23.2.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
《rocky linux:安装pytorch(pytorch 2.0.1 / Python 3.9.16)》有1条评论