1.新建环境
2.激活环境
3.安装pytorch包
4.测试
一、新建环境
conda create -n pytorch37 python=3.7
%%建一个python为3.7,名字叫pytorch37的房子,一定要记得
%%新建环境格式为conda create -n 房子名 python=3.7
下面光标开始闪烁
Solving environment: done
%%光标在这里闪烁
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 22.9.0
Please update conda by running
$ conda update -n base -c defaults conda
%%这个后面可以更行一下conda版本
## Package Plan ##
environment location: D:\Anaconda\envs\pytorch37
added / updated specs:
- python=3.7
The following NEW packages will be INSTALLED:
ca-certificates: 2022.07.19-haa95532_0
certifi: 2022.9.24-py37haa95532_0
openssl: 1.1.1q-h2bbff1b_0
pip: 22.2.2-py37haa95532_0
python: 3.7.13-h6244533_1
setuptools: 63.4.1-py37haa95532_0
sqlite: 3.39.3-h2bbff1b_0
vc: 14.2-h21ff451_1
vs2015_runtime: 14.27.29016-h5e58377_2
wheel: 0.37.1-pyhd3eb1b0_0
wincertstore: 0.2-py37haa95532_2
输入Y
Proceed ([y]/n)? y
开始安装工具包,可能有点慢
完成后显示
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate pytorch37
#
# To deactivate an active environment, use
#
# $ conda deactivate
二、激活环境
(base) C:\Users\Administrator>conda activate pytorch37
%%激活刚才新建环境
(pytorch37) C:\Users\Administrator>
三、安装pytorch包
显卡cuda版本,以及去pytorch官网查看显卡cuda版本对应的pytorch版本
查看方式一:自己电脑显卡cuda版本,如下图
右击----控制面板
帮助—系统信息-----组件,这里显示 cuda是11.4
查看方式二:输入直接看
(pytorch37) C:\Users\Administrator>nvidia-smi
%%输入代码直接查看
Tue Oct 25 11:19:04 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 473.34 Driver Version: 473.34 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... WDDM | 00000000:01:00.0 N/A | N/A |
| 23% 0C P8 N/A / N/A | 420MiB / 2048MiB | N/A Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
(pytorch37) C:\Users\Administrator>
在官网选择cuda是11.4版及11.4版以下都行
这里我选择了11.3的
下面两种方式都可以
%%第一种
(pytorch37) C:\Users\Administrator>conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
或者
%%依次分别执行这三条命令,这是上一步图片红圆圈代码截取
pip install torch==1.12.0
pip install torchvision==0.13.0
pip install torchaudio==0.12.0
第一种运行如下
(pytorch37) C:\Users\Administrator>conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
%%下载时把-c pytorch去掉默认清华镜像源,网速快一点,这里面包大小加起来2.2真的慢。
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 22.9.0
Please update conda by running
$ conda update -n base -c defaults conda
%%更新当前conda版本,回到base环境下更新
## Package Plan ##
environment location: D:\Anaconda\envs\pytorch37
added / updated specs:
- cudatoolkit=11.3
- pytorch
- torchaudio
- torchvision
The following packages will be downloaded:
package | build
---------------------------|-----------------
brotlipy-0.7.0 |py37h2bbff1b_1003 372 KB
pycparser-2.21 | pyhd3eb1b0_0 94 KB
lerc-3.0 | hd77b12b_0 142 KB
typing_extensions-4.3.0 | py37haa95532_0 43 KB
libwebp-1.2.4 | h2bbff1b_0 76 KB
libpng-1.6.37 | h2a8f88b_0 598 KB
zlib-1.2.13 | h8cc25b3_0 145 KB
numpy-1.21.5 | py37h7a0a035_3 24 KB
torchaudio-0.12.1 | py37_cu113 3.7 MB pytorch
libuv-1.40.0 | he774522_0 332 KB
win_inet_pton-1.1.0 | py37haa95532_0 33 KB
lz4-c-1.9.3 | h2bbff1b_1 141 KB
six-1.16.0 | pyhd3eb1b0_1 19 KB
numpy-base-1.21.5 | py37hca35cd5_3 5.6 MB
idna-3.4 | py37haa95532_0 108 KB
zstd-1.5.2 | h19a0ad4_0 1.3 MB
freetype-2.10.4 | hd328e21_0 490 KB
requests-2.28.1 | py37haa95532_0 100 KB
pytorch-mutex-1.0 | cuda 3 KB pytorch
mkl_random-1.2.2 | py37hf11a4ad_0 249 KB
intel-openmp-2021.4.0 | haa95532_3556 3.2 MB
libdeflate-1.8 | h2bbff1b_5 62 KB
cffi-1.15.1 | py37h2bbff1b_0 221 KB
torchvision-0.13.1 | py37_cu113 6.0 MB pytorch
urllib3-1.26.12 | py37haa95532_0 178 KB
mkl_fft-1.3.1 | py37h277e83a_0 154 KB
charset-normalizer-2.0.4 | pyhd3eb1b0_0 33 KB
mkl-2021.4.0 | haa95532_640 181.6 MB
jpeg-9e | h2bbff1b_0 374 KB
cudatoolkit-11.3.1 | h59b6b97_2 820.7 MB
tk-8.6.12 | h2bbff1b_0 3.5 MB
mkl-service-2.4.0 | py37h2bbff1b_0 55 KB
xz-5.2.6 | h8cc25b3_0 364 KB
pytorch-1.12.1 |py3.7_cuda11.3_cudnn8_0 1.19 GB pytorch
cryptography-38.0.1 | py37h21b164f_0 1.1 MB
libwebp-base-1.2.4 | h2bbff1b_0 327 KB
pyopenssl-22.0.0 | pyhd3eb1b0_0 49 KB
libtiff-4.4.0 | h8a3f274_0 1.1 MB
pillow-9.2.0 | py37hdc2b20a_1 1.0 MB
pysocks-1.7.1 | py37_1 27 KB
------------------------------------------------------------
Total: 2.20 GB
The following NEW packages will be INSTALLED:
blas: 1.0-mkl
brotlipy: 0.7.0-py37h2bbff1b_1003
cffi: 1.15.1-py37h2bbff1b_0
charset-normalizer: 2.0.4-pyhd3eb1b0_0
cryptography: 38.0.1-py37h21b164f_0
cudatoolkit: 11.3.1-h59b6b97_2
freetype: 2.10.4-hd328e21_0
idna: 3.4-py37haa95532_0
intel-openmp: 2021.4.0-haa95532_3556
jpeg: 9e-h2bbff1b_0
lerc: 3.0-hd77b12b_0
libdeflate: 1.8-h2bbff1b_5
libpng: 1.6.37-h2a8f88b_0
libtiff: 4.4.0-h8a3f274_0
libuv: 1.40.0-he774522_0
libwebp: 1.2.4-h2bbff1b_0
libwebp-base: 1.2.4-h2bbff1b_0
lz4-c: 1.9.3-h2bbff1b_1
mkl: 2021.4.0-haa95532_640
mkl-service: 2.4.0-py37h2bbff1b_0
mkl_fft: 1.3.1-py37h277e83a_0
mkl_random: 1.2.2-py37hf11a4ad_0
numpy: 1.21.5-py37h7a0a035_3
numpy-base: 1.21.5-py37hca35cd5_3
pillow: 9.2.0-py37hdc2b20a_1
pycparser: 2.21-pyhd3eb1b0_0
pyopenssl: 22.0.0-pyhd3eb1b0_0
pysocks: 1.7.1-py37_1
pytorch: 1.12.1-py3.7_cuda11.3_cudnn8_0 pytorch
pytorch-mutex: 1.0-cuda pytorch
requests: 2.28.1-py37haa95532_0
six: 1.16.0-pyhd3eb1b0_1
tk: 8.6.12-h2bbff1b_0
torchaudio: 0.12.1-py37_cu113 pytorch
torchvision: 0.13.1-py37_cu113 pytorch
typing_extensions: 4.3.0-py37haa95532_0
urllib3: 1.26.12-py37haa95532_0
win_inet_pton: 1.1.0-py37haa95532_0
xz: 5.2.6-h8cc25b3_0
zlib: 1.2.13-h8cc25b3_0
zstd: 1.5.2-h19a0ad4_0
Proceed ([y]/n)?
输入y下载
下载完成后
(pytorch37) C:\Users\Administrator> conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
%%可以尝试在输一遍,所有包安装完成
Solving environment: done
==> WARNING: A newer version of conda exists. <==
current version: 4.5.11
latest version: 22.9.0
Please update conda by running
$ conda update -n base -c defaults conda
# All requested packages already installed.
%%这里我想更新以下主环境里Anaconda版本,你们可更新可跳过
(base) C:\Users\Administrator>conda update -n base -c defaults conda
%%光标闪烁
%%输入y
%%等待下载
%%下载更新完成
四、测试
重新打开进入测试
%%查看环境
(base) C:\Users\Administrator>conda info -e
# conda environments:
#
base * D:\Anaconda
lablimg1 D:\Anaconda\envs\lablimg1
pytorch37 D:\Anaconda\envs\pytorch37
%%进入环境
(base) C:\Users\Administrator>conda activate pytorch37
%%测试
(pytorch37) C:\Users\Administrator>python
Python 3.7.13 (default, Oct 19 2022, 10:19:43) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> exit(0)
(pytorch37) C:\Users\Administrator>
接下一篇内容使用现成数据集跑一个深度学习