SoFunction
Updated on 2024-10-30

Anaconda graphic tutorial for configuring pytorch-gpu virtual environment

1、Update NVIDIA driver

Choose the driver that corresponds to your graphics card (choose the studio version, not the game version).

2, add Anaconda Tsinghua mirror

Method 1: anaconda command replacement

conda config --add channels /anaconda/cloud/conda-forge 
conda config --add channels /anaconda/cloud/msys2
conda config --add channels /anaconda/cloud/pytorch/
conda config --add channels /anaconda/pkgs/r
conda config --add channels /anaconda/pkgs/free
conda config --add channels /anaconda/pkgs/main
conda config --set show_channel_urls yes

(Mark) Switch back to the default source code:

conda config --remove-key channels

Method 2: Replace .condarc

show_channel_urls: true
channel_alias: /anaconda
default_channels:
 - /anaconda/pkgs/main
 - /anaconda/pkgs/free
 - /anaconda/pkgs/r
 - /anaconda/pkgs/pro
 - /anaconda/pkgs/msys2
 - /anaconda/cloud/pytorch/
custom_channels:
 conda-forge: /anaconda/cloud
 msys2: /anaconda/cloud
 bioconda: /anaconda/cloud
 menpo: /anaconda/cloud
 pytorch: /anaconda/cloud
 simpleitk: /anaconda/cloud

3. Create a virtual environment

establish:
conda create -n environmental name python=
opens:
activate environmental name
cloture:
conda deactivate
removing:
conda remove -n environmental name --all
Add Packages:
conda install -n environmental name package name
Removal Packages:
conda remove -n environmental name package name

4. Installation of pytorch commands - corresponds to the situation of choice: link to the command code (pytorch official website)

Installation (recommended)

pip install torch===1.4.0 torchvision===0.5.0 -f /whl/torch_stable.html

This one's more stable than the conda, and hitting enter when it gets stuck seems to save the day.

Installation (not recommended, always interrupted)

conda install pytorch torchvision cudatoolkit=10.1 -c pytorch (To remove-c pytorch Otherwise, it's still the default source.)
The final input command:
conda install pytorch torchvision cudatoolkit=10.1

The network's down all over the place. Sometimes it's down again at 48%.

Test after installation

import torch
flag = .is_available()
print(flag)
 
ngpu= 1
# Decide which device we want to run on
device = ("cuda:0" if (.is_available() and ngpu > 0) else "cpu")
print(device)
print(.get_device_name(0))
print((3,3).cuda())

Result: after being tossed around by the conda command all afternoon, I was finally rescued by the pip command!

summarize

To this Anaconda configuration pytorch-gpu virtual environment steps to organize the article is introduced to this, more related to Anaconda pytorch-gpu virtual environment content, please search for my previous articles or continue to browse the following related articles I hope you will support me in the future more!