(conda + pip) Configurar el entorno de aprendizaje profundo de cada versión de Pytorch

1. Introducción

  • Cuando se utiliza Anaconda para configurar el entorno de aprendizaje profundo de Pytorch, las instrucciones de instalación proporcionadas por el enlace del sitio web oficial serán muy lentas y a menudo se informarán errores. Con este fin, se compila la versión principal actual de las instrucciones de configuración del entorno de aprendizaje profundo de Pytorch. Las instrucciones son adecuadas para los sistemas operativos Windows y se ejecutan en Anaconda Prompt .
  • Además, a veces se informará un error al utilizar conda para la instalación. El artículo incluye instrucciones de instalación de pip. Dado que el método de instalación de pip proporcionado en el sitio web oficial es algo hostil, se han realizado ciertas mejoras en el artículo. La mayoría de las instrucciones son efectivos después de pruebas personales.

Insertar descripción de la imagen aquí

2. Configurar la fuente espejo

Déjame decirte de antemano : si se informa un error HTTP después de configurar la fuente espejo, solo necesitas eliminar el correo electrónico en https://... en el enlace de la fuente
.

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/ 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
conda config --set show_channel_urls yes

Dayuan de Ciencia y Tecnología de China

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --set show_channel_urls yes

3. Versiones correspondientes de pytorch, torchvision y python

La relación correspondiente entre pytorch, torchvision y python proviene del github oficial de pytorch, enlace: https://github.com/pytorch/vision#installation

Insertar descripción de la imagen aquí

4. Crea e ingresa al entorno virtual.

Cree un entorno virtual, donde pt es el nombre del entorno virtual personalizado. Además, según la experiencia con errores, la versión python 3.6.5 puede adaptarse a más versiones de pytorch y algunos paquetes adicionales. Se recomienda seleccionar la versión 3.6.5 para la versión del intérprete de Python al crear un entorno.

conda create -n pt python=3.6.5

Luego haga clic en y para aceptar la instalación y espere un momento para ingresar al entorno virtual.

activate pt

5.Pytorch 0.4.1

# conda
conda install pytorch==0.4.1 torchvision==0.2.1 cuda90  # CUDA 9.0
conda install pytorch==0.4.1 torchvision==0.2.1 cuda92  # CUDA 9.2
conda install pytorch==0.4.1 torchvision==0.2.1 cuda80  # CUDA 8.0
conda install pytorch==0.4.1 torchvision==0.2.1 cuda75  # CUDA 7.5
conda install pytorch==0.4.1 torchvision==0.2.1 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu90/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 9.0
pip install https://download.pytorch.org/whl/cu92/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 9.2
pip install https://download.pytorch.org/whl/cu80/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 8.0
pip install https://download.pytorch.org/whl/cu75/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 7.5
pip install https://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CPU 版本

6.Pytorch 1.0.0

# conda
conda install pytorch==1.0.0 torchvision==0.2.1 cuda100  # CUDA 10.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda90  # CUDA 9.0
conda install pytorch==1.0.0 torchvision==0.2.1 cuda80  # CUDA 8.0
conda install pytorch-cpu==1.0.0 torchvision-cpu==0.2.1 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu100/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 10.0
pip install https://download.pytorch.org/whl/cu90/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 9.0
pip install https://download.pytorch.org/whl/cu80/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CUDA 8.0
pip install https://download.pytorch.org/whl/cpu/torch-1.0.0-cp36-cp36m-win_amd64.whl torchvision==0.2.1  # CPU 版本

7.Pytorch 1.0.1

# conda
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=10.0  # CUDA 10.0
conda install pytorch==1.0.1 torchvision==0.2.2 cudatoolkit=9.0  # CUDA 9.0
conda install pytorch-cpu==1.0.1 torchvision-cpu==0.2.2 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu100/torch-1.0.1-cp36-cp36m-win_amd64.whl torchvision==0.2.2  # CUDA 10.0
pip install https://download.pytorch.org/whl/cu90/torch-1.0.1-cp36-cp36m-win_amd64.whl torchvision==0.2.2  # CUDA 9.0
pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp36-cp36m-win_amd64.whl torchvision==0.2.2  # CPU 版本

8.Pytorch 1.1.0

# conda
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0  # CUDA 10.0
conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0  # CUDA 9.0
conda install pytorch-cpu==1.1.0 torchvision-cpu==0.3.0 cpuonly  # CPU 版本
# pip
pip install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp36-cp36m-win_amd64.whl torchvision==0.3.0  # CUDA 10.0
pip install https://download.pytorch.org/whl/cu90/torch-1.1.0-cp36-cp36m-win_amd64.whl torchvision==0.3.0  # CUDA 9.0
pip install https://download.pytorch.org/whl/cpu/torch-1.1.0-cp36-cp36m-win_amd64.whl torchvision==0.3.0  # CPU 版本

9.Pytorch 1.2.0

# conda
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0  # CUDA 10.0
conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.2.0 torchvision==0.4.0 cpuonly  # CPU 版本
# pip
pip install torch==1.2.0+cu100 torchvision==0.4.0+cu100 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.0
pip install torch==1.2.0+cu92 torchvision==0.4.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.2.0+cpu torchvision==0.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

10.Pytorch 1.4.0

# conda
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.4.0 torchvision==0.5.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.4.0 torchvision==0.5.0 cpuonly  # CPU 版本
# pip
pip install torch==1.4.0+cu101 torchvision==0.5.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.4.0+cu92 torchvision==0.5.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

11.Pytorch 1.5.0

# conda
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.5.0 torchvision==0.6.0 cpuonly  # CPU 版本
# pip
pip install torch==1.5.0+cu102 torchvision==0.6.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.5.0+cu101 torchvision==0.6.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.5.0+cu92 torchvision==0.6.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

12.Pytorch 1.5.1

# conda
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.5.1 torchvision==0.6.1 cpuonly  # CPU 版本
# pip
pip install torch==1.5.1+cu102 torchvision==0.6.1+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.5.1+cu101 torchvision==0.6.1+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.5.1+cu92 torchvision==0.6.1+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.5.1+cpu torchvision==0.6.1+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

13.Pytorch 1.6.0

# conda
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.6.0 torchvision==0.7.0 cpuonly  # CPU 版本
# pip
pip install torch==1.6.0+cu102 torchvision==0.7.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.6.0+cu92 torchvision==0.7.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

14.Pytorch 1.7.0

# conda
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=11.0  # CUDA 11.0
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.7.0 torchvision==0.8.0 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.7.0 torchvision==0.8.0 cpuonly  # CPU 版本
# pip
pip install torch==1.7.0+cu110 torchvision==0.8.0+cu110 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.0
pip install torch==1.7.0+cu102 torchvision==0.8.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.7.0+cu101 torchvision==0.8.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.7.0+cu92 torchvision==0.8.0+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.7.0+cpu torchvision==0.8.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

15.Pytorch 1.7.1

# conda
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=11.0  # CUDA 11.0
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=10.1  # CUDA 10.1
conda install pytorch==1.7.1 torchvision==0.8.2 cudatoolkit=9.2  # CUDA 9.2
conda install pytorch==1.7.1 torchvision==0.8.2 cpuonly  # CPU 版本
# pip

pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.0
pip install torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.1
pip install torch==1.7.1+cu92 torchvision==0.8.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 9.2
pip install torch==1.7.1+cpu torchvision==0.8.2+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

16.Pytorch 1.8.0

# conda
conda install pytorch==1.8.0 torchvision==0.9.0 cudatoolkit=11.1  # CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.8.0 torchvision==0.9.0 cpuonly  # CPU 版本
# pip
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.1
pip install torch==1.8.0+cu102 torchvision==0.9.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.8.0+cpu torchvision==0.9.0+cpu0 -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

17.Pytorch 1.9.0

# conda
conda install pytorch==1.9.0 torchvision==0.10.0 cudatoolkit=11.1  # CUDA 11.1
conda install pytorch==1.9.0 torchvision==0.10.0 cudatoolkit=10.2  # CUDA 10.2
conda install pytorch==1.9.0 torchvision==0.10.0 cpuonly  # CPU 版本
# pip
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 11.1
pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 -f https://download.pytorch.org/whl/torch_stable.html  # CUDA 10.2
pip install torch==1.9.0+cpu torchvision==0.10.0+cpu -f https://download.pytorch.org/whl/torch_stable.html  # CPU 版本

18. Pruebe si la instalación se realizó correctamente.

  • Prueba de versión de CPU: continúe ejecutando Python para ingresar al entorno interactivo y ejecútelos por separado import torch. import torchvisionSi no se informa ningún error, la instalación se realizó correctamente.
  • Prueba de versión de GPU: continúe ejecutando Python para ingresar al entorno interactivo, ejecútelos por separado sin import torchinformar import torchvisionun error y ejecútelo nuevamente print(torch.cuda.is_available()). Si se genera True, la instalación se realizó correctamente.

Insertar descripción de la imagen aquí

Supongo que te gusta

Origin blog.csdn.net/Wenyuanbo/article/details/119382460
Recomendado
Clasificación