Conda instalar Pytorch

1. entorno virtual del conmutador de conda

activate 虚拟环境名称
C:\Windows\System32>activate python310

Recordatorio: consulta la lista de entornos virtuales

conda env list
C:\Windows\System32>conda env list
# conda environments:
#
base                     D:\anaconda3
python310                D:\anaconda3\envs\python310

2. fuente de instalación de vista conda

conda config --show-sources

Mi fuente de instalación local es: Tsinghua University Open Source Software Mirror Source

Para modificar la fuente de instalación predeterminada de conda, ejecute el siguiente comando:

# 安装清华安装源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
 
# 移除conda 默认安装源
conda config --remove channels defaults

3. conda Ver versión de PyTorch

conda search pytorch
(python310) C:\Windows\System32>conda search pytorch
Loading channels: done
# Name                       Version           Build  Channel
pytorch                        1.0.1 cpu_py36h39a92a0_0  pkgs/main
pytorch                        1.0.1 cpu_py37h39a92a0_0  pkgs/main
pytorch                        1.3.1 cpu_py36h9f948e0_0  pkgs/main
pytorch                        1.3.1 cpu_py37h9f948e0_0  pkgs/main
pytorch                        1.4.0 cpu_py36ha775e86_0  pkgs/main
pytorch                        1.4.0 cpu_py37ha775e86_0  pkgs/main
pytorch                        1.4.0 cpu_py38ha775e86_0  pkgs/main
pytorch                        1.5.0 cpu_py37h9f948e0_0  pkgs/main
pytorch                        1.6.0 cpu_py37h538a6d7_0  pkgs/main
pytorch                        1.6.0 cpu_py38h538a6d7_0  pkgs/main
pytorch                       1.10.2 cpu_py310habb1308_0  pkgs/main
pytorch                       1.10.2 cpu_py37h907fbb5_0  pkgs/main
pytorch                       1.10.2 cpu_py38h907fbb5_0  pkgs/main
pytorch                       1.10.2 cpu_py39h907fbb5_0  pkgs/main
pytorch                       1.12.1 cpu_py310h5e1f01c_0  pkgs/main
pytorch                       1.12.1 cpu_py310h5e1f01c_1  pkgs/main
pytorch                       1.12.1 cpu_py37h5e1f01c_0  pkgs/main
pytorch                       1.12.1 cpu_py37h5e1f01c_1  pkgs/main
pytorch                       1.12.1 cpu_py38h5e1f01c_0  pkgs/main
pytorch                       1.12.1 cpu_py38h5e1f01c_1  pkgs/main
pytorch                       1.12.1 cpu_py39h5e1f01c_0  pkgs/main
pytorch                       1.12.1 cpu_py39h5e1f01c_1  pkgs/main

4. Instalar PyTorch

Según su propia versión de instalación, busque el código de comando de instalación en el sitio web oficial de Pytorch:
(1) Sitio web oficial de Pytorch: PyTorch

 La versión que se muestra en la figura copiará las instrucciones pertinentes:

conda install pytorch torchvision torchaudio cpuonly -c pytorch

(2) Pegue el código copiado en el formato de línea de comando, aparecerá un mensaje emergente, ingrese y para completar la instalación y se mostrará "hecho".

(python310) C:\Windows\System32>conda install pytorch torchvision torchaudio cpuonly -c pytorch
Retrieving notices: ...working... done
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: D:\anaconda3\envs\python310

  added / updated specs:
    - cpuonly
    - pytorch
    - torchaudio
    - torchvision


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2023.5.7           |  py310haa95532_0         153 KB  defaults
    cpuonly-2.0                |                0           2 KB  pytorch
    pytorch-2.0.1              |     py3.10_cpu_0       145.5 MB  pytorch
    pytorch-mutex-1.0          |              cpu           3 KB  pytorch
    torchaudio-2.0.2           |        py310_cpu         5.4 MB  pytorch
    torchvision-0.15.2         |        py310_cpu         6.5 MB  pytorch
    ------------------------------------------------------------
                                           Total:       157.6 MB

The following NEW packages will be INSTALLED:

  cpuonly            pytorch/noarch::cpuonly-2.0-0
  filelock           pkgs/main/win-64::filelock-3.9.0-py310haa95532_0
  jinja2             pkgs/main/win-64::jinja2-3.1.2-py310haa95532_0
  libuv              pkgs/main/win-64::libuv-1.44.2-h2bbff1b_0
  markupsafe         pkgs/main/win-64::markupsafe-2.1.1-py310h2bbff1b_0
  mpmath             pkgs/main/win-64::mpmath-1.2.1-py310haa95532_0
  networkx           pkgs/main/win-64::networkx-2.8.4-py310haa95532_1
  pytorch            pytorch/win-64::pytorch-2.0.1-py3.10_cpu_0
  pytorch-mutex      pytorch/noarch::pytorch-mutex-1.0-cpu
  sympy              pkgs/main/win-64::sympy-1.11.1-py310haa95532_0
  torchaudio         pytorch/win-64::torchaudio-2.0.2-py310_cpu
  torchvision        pytorch/win-64::torchvision-0.15.2-py310_cpu
  typing_extensions  pkgs/main/win-64::typing_extensions-4.5.0-py310haa95532_0

The following packages will be UPDATED:

  certifi                         2022.12.7-py310haa95532_0 --> 2023.5.7-py310haa95532_0


Proceed ([y]/n)? y


Downloading and Extracting Packages

Preparing transaction: done
Verifying transaction: done
Executing transaction: done

(3) verificación del módulo pytorch

1. Introduzca pitón: pitón

2. Test pytorch: importar  antorcha

(python310) C:\Windows\System32>python
Python 3.10.10 | packaged by Anaconda, Inc. | (main, Mar 21 2023, 18:39:17) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> 

Supongo que te gusta

Origin blog.csdn.net/zhouzhiwengang/article/details/130739859
Recomendado
Clasificación