复制最后一句
conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
创建虚拟环境
(base) C:\Users\Administrator>conda create -n pytorch python=3.8
Channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: done
## Package Plan ##
environment location: d:\anaconda3\envs\pytorch
added / updated specs:
- python=3.8
The following packages will be downloaded:
package | build
---------------------------|-----------------
pip-24.0 | py38haa95532_0 2.8 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
python-3.8.19 | h1aa4202_0 18.9 MB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
setuptools-69.5.1 | py38haa95532_0 1003 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
wheel-0.43.0 | py38haa95532_0 137 KB https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
------------------------------------------------------------
Total: 22.9 MB
The following NEW packages will be INSTALLED:
ca-certificates anaconda/pkgs/main/win-64::ca-certificates-2024.3.11-haa95532_0
libffi anaconda/pkgs/main/win-64::libffi-3.4.4-hd77b12b_1
openssl anaconda/pkgs/main/win-64::openssl-3.0.13-h2bbff1b_2
pip anaconda/pkgs/main/win-64::pip-24.0-py38haa95532_0
python anaconda/pkgs/main/win-64::python-3.8.19-h1aa4202_0
setuptools anaconda/pkgs/main/win-64::setuptools-69.5.1-py38haa95532_0
sqlite anaconda/pkgs/main/win-64::sqlite-3.45.3-h2bbff1b_0
vc anaconda/pkgs/main/win-64::vc-14.2-h2eaa2aa_1
vs2015_runtime anaconda/pkgs/main/win-64::vs2015_runtime-14.29.30133-h43f2093_3
wheel anaconda/pkgs/main/win-64::wheel-0.43.0-py38haa95532_0
Proceed ([y]/n)? y
Downloading and Extracting Packages:
python-3.8.19 | 18.9 MB | ##########################################################################3 | 98%
pip-24.0 | 2.8 MB | ############################################################################ | 100%
setuptools-69.5.1 | 1003 KB | ############################################################################ | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate pytorch
#
# To deactivate an active environment, use
#
# $ conda deactivate
(base) C:\Users\Administrator>
(pytorch) C:\Users\Administrator>conda install pytorch torchvision torchaudio pytorch-cuda=12.1 -c pytorch -c nvidia
漫长的等待。
测试是否成功。
done
(pytorch) C:\Users\Administrator>python
Python 3.8.19 (default, Mar 20 2024, 19:55:45) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'2.3.0'
>>> x=torch.rand(5)
>>> print(x)
tensor([0.0358, 0.8986, 0.6291, 0.2144, 0.4557])
>>> torch.cuda.is_available()
True
>>>