1、conda 切换虚拟环境
activate 虚拟环境名称
C:\Windows\System32>activate python310
温馨提示:查询虚拟环境列表
conda env list
C:\Windows\System32>conda env list
# conda environments:
#
base D:\anaconda3
python310 D:\anaconda3\envs\python310
2、conda 查看安装源
conda config --show-sources
我本地安装源为:清华大学开源软件镜像源
修改conda 默认安装源,请执行如下指令:
# 安装清华安装源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 移除conda 默认安装源
conda config --remove channels defaults
3、conda 查看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、安装PyTorch
根据自己的安装版本,在Pytorch官网寻找安装命令代码:
(1)Pytorch官网:PyTorch
如图所示版本将相关指令复制:
conda install pytorch torchvision torchaudio cpuonly -c pytorch
(2)将复制的代码粘贴到命令行格式下,弹出提示,输入 y,即可完成安装,显示“done”。
(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)pytorch 模块验证
1.进入python:python
2.测试pytorch:import torch
(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
>>>