pytorch+torchvision+python版本對(duì)應(yīng)及環(huán)境安裝
一、版本對(duì)應(yīng)
下表來自 pytorch 的 github 官方文檔:pytorch/vision: Datasets, Transforms and Models specific to Computer Vision
- pytorch 安裝官網(wǎng):Start Locally | PyTorch
- pytorch 之前版本的安裝命令:Previous PyTorch Versions | PyTorch
- torch、torchvision 等相關(guān)庫(kù):download.pytorch.org/whl/torch_stable.html
其中,命令中 "-c pytorch" 表示官方源,自己換源可以去掉。
torch 版本 | torchvision 版本 | torchaudio 版本 | 支持的 Python 版本(示例) | Cuda 版本 |
---|---|---|---|---|
2.5.1 | 0.20.1 | 2.5.1 | >=3.9, <3.13(3.12)[9/10/11/12] | 12.4/12.1/11.8 |
2.5.0 | 0.20.0 | 2.5.0 | >=3.9, <3.13(3.12) | 12.4/12.1/11.8 |
2.4.1 | 0.19.1 | 2.4.1 | >=3.8, <3.13(3.12)[8/9/10/11/12] | 12.4/12.1/11.8 |
2.4.0 | 0.19.0 | 2.4.0 | >=3.8, <3.13(3.12) | 12.4/12.1/11.8 |
2.3.1 | 0.18.1 | 2.3.1 | >=3.8, <3.13(3.12)8/9/10/11/12 | 12.1/11.8 |
2.3.0 | 0.18.0 | 2.3.0 | >=3.8, <3.13(3.12) | 12.1/11.8 |
2.2.2 | 0.17.2 | 2.2.2 | >=3.8, <3.12 [8/9/10/11] | 12.1/11.8 |
2.2.1 | 0.17.1 | 2.2.1 | >=3.8, <3.12 | 12.1/11.8 |
2.2.0 | 0.17.0 | 2.2.0 | >=3.8, <3.12 | 12.1/11.8 |
2.1.2 | 0.16.2 | 2.1.2 | >=3.8, <3.12(3.10)8/9/10/11 | 12.1/11.8 |
2.1.1 | 0.16.1 | 2.1.1 | >=3.8, <3.12(3.10) | 12.1/11.8 |
2.1.0 | 0.16.0 | 2.1.0 | >=3.8, <3.12(3.10) | 12.1/11.8 |
2.0.0 | 0.15.0 | 2.0.0 | >=3.8, <3.12(3.8)[8/9/10/11] | 11.8/11.7 |
1.13.1 | 0.14.1 | 0.13.1 | >=3.7.2, <=3.10(3.8)[7/8/9/10] | 11.7/11.6 |
1.13.0 | 0.14.0 | 0.13.0 | >=3.7.2, <=3.10(3.8) | 11.7/11.6 |
1.12.1 | 0.13.1 | 1.12.1 | >=3.7, <=3.10(3.8)[7/8/9/10] | 11.6/11.3/10.2 |
1.12.0 | 0.13.0 | 1.12.0 | >=3.7, <=3.10(3.8) | 11.6/11.3/10.2 |
1.11.0 | 0.12.0 | 1.11.0 | >=3.7, <=3.10(3.8) | 11.3/10.2 |
1.10.1 | 0.11.2 | 0.10.1 | >=3.6, <=3.9(3.8)[6/7/8/9] | 11.3/10.2 |
1.10.0 | 0.11.0 | 0.10.0 | >=3.6, <=3.9(3.8) | 11.3/10.2 |
1.9.1 | 0.10.1 | 0.9.1 | >=3.6, <=3.9(3.8)[6/7/8/9] | 11.1/10.2 |
1.9.0 | 0.10.0 | 0.9.0 | >=3.6, <=3.9(3.8) | 11.1/10.2 |
1.8.1 | 0.9.1 | 0.8.1 | >=3.6, <=3.9(3.8)[6/7/8/9] | 11.1/10.2 |
1.8.0 | 0.9.0 | 0.8.0 | >=3.6, <=3.9(3.8) | 11.1/10.2 |
1.7.1 | 0.8.2 | 0.7.2 | >=3.6(3.6) | 11.0/10.2/10.1 |
1.7.0 | 0.8.0 | 0.7.0 | >=3.6(3.6) | 11.0/10.2/10.1 |
二、安裝命令(pip)
1. 版本
(1)v2.5.1 ~ v2.0.0
# v2.5.1 # CUDA 12.4 pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cu124 -i https://pypi.tuna.tsinghua.edu.cn/simple/ # CPU only pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cpu -i https://pypi.tuna.tsinghua.edu.cn/simple/
(2)v1.13.1 ~ v1.11.0
# v1.13.1 # CUDA 11.7 pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117 -i https://pypi.tuna.tsinghua.edu.cn/simple/ # CPU only pip install torch==1.13.1+cpu torchvision==0.14.1+cpu torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cpu -i https://pypi.tuna.tsinghua.edu.cn/simple/
(3)v1.10.1 ~ v1.7.0
# v1.10.1 # CUDA 10.2 pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 -f https://download.pytorch.org/whl/cu102/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple/ # CPU only pip install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple/
2. 安裝全過程
(1)選擇版本
torch 版本 | torchvision 版本 | torchaudio 版本 | 支持的 Python 版本(示例) | Cuda 版本 |
---|---|---|---|---|
2.1.0 | 0.16.0 | 2.1.0 | >=3.8, <3.12(3.10) | 12.1/11.8 |
這里選擇的框架和環(huán)境如下:torch2.1.0 | torchvision0.16.0 | torchaudio2.1.0 | python3.10 | Cuda12.1,若需要將創(chuàng)建的虛擬環(huán)境添加到 Jupyter Lab / Jupyter Notebook 中使用,則需要第 3-6 步,否則不用。
打開 WIN + R,輸入 “cmd”,進(jìn)入命令行窗口,其他步驟如下:
# 1. Anaconda 創(chuàng)建虛擬環(huán)境 conda create -n torch python=3.10 # 2. 激活并進(jìn)入虛擬環(huán)境 activate torch # 3. 安裝 ipykernel pip install ipykernel -i https://pypi.tuna.tsinghua.edu.cn/simple/ # 4. 安裝ipykernel,將虛擬環(huán)境加入 jupyter 內(nèi)核中 python -m ipykernel install --name torch --display-name torch # 5. 檢查新虛擬環(huán)境是否成功加入內(nèi)核 jupyter kernelspec list # 6. 從指定文件夾里進(jìn)入 jupyter jupyter lab # 7. 安裝 torch 等軟件包 pip install torch==2.1.0 torchvision==0.16.0 torchaudio==2.1.0 --index-url https://download.pytorch.org/whl/cpu -i https://pypi.tuna.tsinghua.edu.cn/simple/
注意:此時(shí),因?yàn)?Numpy 2.x 等其他的相關(guān)庫(kù) 與 Pytorch 2.1.0 的不兼容(以 Numpy 庫(kù)為例),所以需要將 numpy 庫(kù)的版本降級(jí)至1.x.x(如 1.24.x 或 1.23.x 版本)才能與 Pytorch 2.1.0 是兼容,從而適配以上版本。具體示例步驟如下:
- pip uninstall numpy
- pip install numpy==1.24.3
注意:若在安裝途中不小心關(guān)閉了命令窗或者發(fā)現(xiàn)沒有關(guān)閉梯子,可先將 Anaconda 的環(huán)境中刪除未完全安裝好的虛擬環(huán)境(如在 E:\Anaconda\envs\torch 此目錄下),即可重新進(jìn)行上述安裝步驟。
(2)安裝結(jié)果
3. 命令相關(guān)解釋
(1)-i / --index-url
第一條命令:pip install torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 --index-url https://download.pytorch.org/whl/cpu -i https://pypi.tuna.tsinghua.edu.cn/simple/
--index-url https://download.pytorch.org/whl/cpu
:這個(gè)參數(shù)指定了主要的包索引源 URL,即使用https://download.pytorch.org/whl/cpu
作為 PyTorch 相關(guān)庫(kù)的包來源。這是 PyTorch 官方的 CPU 版本的二進(jìn)制文件源。-i https://pypi.tuna.tsinghua.edu.cn/simple/
:這個(gè)參數(shù)指定了鏡像源,指向清華大學(xué)的 PyPI 鏡像源,以加速?gòu)?PyPI 安裝包的速度。- 當(dāng)同時(shí)使用
--index-url
和-i
時(shí),--index-url
會(huì)設(shè)置 主索引源(比如官方 PyTorch 或其他自定義源),而-i
用來指定 一個(gè)額外的索引源 / 備用源(如清華鏡像)。此時(shí),pip
會(huì)先從--index-url
指定的源查找包,如果找不到,才會(huì)去-i
指定的額外源查找。
(2)--extra-index-url
第二條命令:pip install torch==1.13.1+cpu torchvision==0.14.1+cpu torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cpu -i https://pypi.tuna.tsinghua.edu.cn/simple/
--extra-index-url https://download.pytorch.org/whl/cpu
:這個(gè)參數(shù)指定了額外的索引源 URL。與--index-url
不同,--extra-index-url
只是添加額外的索引源,而不是替換原有源。此處指定的是 PyTorch 官方 CPU 版本的源。-i https://pypi.tuna.tsinghua.edu.cn/simple/
:同樣指定了 PyPI 鏡像源,指向清華大學(xué)的 PyPI 鏡像源。
(3)-f / --find-links
第三條命令:pip install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1 -f https://download.pytorch.org/whl/cpu/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple/
-f https://download.pytorch.org/whl/cpu/torch_stable.html
:這個(gè)參數(shù)用于指定一個(gè)包的 URL 文件列表(一個(gè).html
或.xml
文件),其中列出了穩(wěn)定版本的 PyTorch 安裝包。-i https://pypi.tuna.tsinghua.edu.cn/simple/
:同樣指定了 PyPI 鏡像源,指向清華大學(xué)的 PyPI 鏡像源。
參考文章
[1] pytorch,torchvision與python版本對(duì)應(yīng)關(guān)系及安裝命令_pytorch python版本-CSDN博客
[2] Python安裝torch(含torch和torchvision對(duì)應(yīng)版本)-CSDN博客
到此這篇關(guān)于pytorch+torchvision+python版本對(duì)應(yīng)及環(huán)境安裝的文章就介紹到這了,更多相關(guān)pytorch torchvision python版本對(duì)應(yīng)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python自動(dòng)化辦公Excel模塊openpyxl原理及用法解析
這篇文章主要介紹了Python自動(dòng)化辦公Excel模塊openpyxl原理及用法解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-11-11教你如何用Pytorch搭建數(shù)英混合驗(yàn)證碼圖片識(shí)別模型
大家都知道checkpoints存放的是模型文件,data存放的是數(shù)據(jù)集,本文給大家分享如何利用Pytorch搭建數(shù)英混合驗(yàn)證碼圖片識(shí)別模型包括普通卷積模塊,深度可分離卷積模塊,空間通道注意力模塊,殘差模塊,感興趣的朋友跟隨小編一起看看吧2024-04-04django連接mysql數(shù)據(jù)庫(kù)及建表操作實(shí)例詳解
這篇文章主要介紹了django連接mysql數(shù)據(jù)庫(kù)及建表操作,結(jié)合實(shí)例形式詳細(xì)分析了Django框架連接mysql數(shù)據(jù)庫(kù)、創(chuàng)建與查詢數(shù)據(jù)表相關(guān)操作實(shí)現(xiàn)技巧,需要的朋友可以參考下2019-12-12Python中Flask-RESTful編寫API接口(小白入門)
這篇文章主要介紹了Python中Flask-RESTful編寫API接口(小白入門),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12