欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

pytorch+torchvision+python版本對(duì)應(yīng)及環(huán)境安裝

 更新時(shí)間:2025年03月16日 10:31:56   作者:半畝花海  
本文主要介紹了pytorch+torchvision+python版本對(duì)應(yīng)及環(huán)境安裝,安裝過程中需要注意Numpy版本的降級(jí),以確保與PyTorch兼容,具有一定的參考價(jià)值,感興趣的可以了解一下

一、版本對(duì)應(yīng)

下表來自 pytorch 的 github 官方文檔:pytorch/vision: Datasets, Transforms and Models specific to Computer Vision

其中,命令中 "-c pytorch" 表示官方源,自己換源可以去掉。

torch 版本torchvision 版本torchaudio 版本支持的 Python 版本(示例)Cuda 版本
2.5.10.20.12.5.1>=3.9, <3.13(3.12)[9/10/11/12]12.4/12.1/11.8
2.5.00.20.02.5.0>=3.9, <3.13(3.12)12.4/12.1/11.8
2.4.10.19.12.4.1>=3.8, <3.13(3.12)[8/9/10/11/12]12.4/12.1/11.8
2.4.00.19.02.4.0>=3.8, <3.13(3.12)12.4/12.1/11.8
2.3.10.18.12.3.1>=3.8, <3.13(3.12)8/9/10/11/1212.1/11.8
2.3.00.18.02.3.0>=3.8, <3.13(3.12)12.1/11.8
2.2.20.17.22.2.2>=3.8, <3.12 [8/9/10/11]12.1/11.8
2.2.10.17.12.2.1>=3.8, <3.1212.1/11.8
2.2.00.17.02.2.0>=3.8, <3.1212.1/11.8
2.1.20.16.22.1.2>=3.8, <3.12(3.10)8/9/10/1112.1/11.8
2.1.10.16.12.1.1>=3.8, <3.12(3.10)12.1/11.8
2.1.00.16.02.1.0>=3.8, <3.12(3.10)12.1/11.8
2.0.00.15.02.0.0>=3.8, <3.12(3.8)[8/9/10/11]11.8/11.7
1.13.10.14.10.13.1>=3.7.2, <=3.10(3.8)[7/8/9/10]11.7/11.6
1.13.00.14.00.13.0>=3.7.2, <=3.10(3.8)11.7/11.6
1.12.10.13.11.12.1>=3.7, <=3.10(3.8)[7/8/9/10]11.6/11.3/10.2
1.12.00.13.01.12.0>=3.7, <=3.10(3.8)11.6/11.3/10.2
1.11.00.12.01.11.0>=3.7, <=3.10(3.8)11.3/10.2
1.10.10.11.20.10.1>=3.6, <=3.9(3.8)[6/7/8/9]11.3/10.2
1.10.00.11.00.10.0>=3.6, <=3.9(3.8)11.3/10.2
1.9.10.10.10.9.1>=3.6, <=3.9(3.8)[6/7/8/9]11.1/10.2
1.9.00.10.00.9.0>=3.6, <=3.9(3.8)11.1/10.2
1.8.10.9.10.8.1>=3.6, <=3.9(3.8)[6/7/8/9]11.1/10.2
1.8.00.9.00.8.0>=3.6, <=3.9(3.8)11.1/10.2
1.7.10.8.20.7.2>=3.6(3.6)11.0/10.2/10.1
1.7.00.8.00.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.00.16.02.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處理變量交換與字符串及判斷的小妙招

    python處理變量交換與字符串及判斷的小妙招

    本文記錄一些 Python 日常編程中的小妙招,并使用 IPython 進(jìn)行交互測(cè)試,讓我們更好的了解和學(xué)習(xí) Python 的一些特性,對(duì)大家的學(xué)習(xí)或工作具有一定的價(jià)值,需要的朋友可以參考下
    2021-09-09
  • Python元組知識(shí)點(diǎn)總結(jié)

    Python元組知識(shí)點(diǎn)總結(jié)

    在本篇文章里小編給大家分享了關(guān)于Python元組的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-02-02
  • 通俗易懂了解Python裝飾器原理

    通俗易懂了解Python裝飾器原理

    這篇文章主要介紹了通俗易懂了解Python裝飾器原理,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-09-09
  • Python自動(dòng)化辦公Excel模塊openpyxl原理及用法解析

    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í)別模型

    教你如何用Pytorch搭建數(shù)英混合驗(yàn)證碼圖片識(shí)別模型

    大家都知道checkpoints存放的是模型文件,data存放的是數(shù)據(jù)集,本文給大家分享如何利用Pytorch搭建數(shù)英混合驗(yàn)證碼圖片識(shí)別模型包括普通卷積模塊,深度可分離卷積模塊,空間通道注意力模塊,殘差模塊,感興趣的朋友跟隨小編一起看看吧
    2024-04-04
  • 詳解Python_shutil模塊

    詳解Python_shutil模塊

    這篇文章主要介紹了Python_shutil模塊功能,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-03-03
  • django連接mysql數(shù)據(jù)庫(kù)及建表操作實(shí)例詳解

    django連接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-12
  • pip install命令安裝擴(kuò)展庫(kù)整理

    pip install命令安裝擴(kuò)展庫(kù)整理

    這篇文章主要介紹了pip install命令安裝擴(kuò)展庫(kù)整理,文中代碼和圖文講解的很詳細(xì),有需要的同學(xué)可以參考下
    2021-03-03
  • Python中Flask-RESTful編寫API接口(小白入門)

    Python中Flask-RESTful編寫API接口(小白入門)

    這篇文章主要介紹了Python中Flask-RESTful編寫API接口(小白入門),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • Anaconda環(huán)境變量的配置圖文詳解

    Anaconda環(huán)境變量的配置圖文詳解

    Anaconda指的是一個(gè)開源的Python發(fā)行版本,其包含了conda、Python等180多個(gè)科學(xué)包及其依賴項(xiàng),下面這篇文章主要給大家介紹了關(guān)于Anaconda環(huán)境變量配置的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-08-08

最新評(píng)論