Anconda virtual environment creation and pytorch installation steps

1. First install python (the version should not be too new), then install the pycharm editor again, try not to reverse the order, some computers will have bugs, which will cause problems when uninstalling

2. Install anconda3 (note that it can automatically configure environment variables during installation to save a lot of unnecessary trouble)

3.win+R input cmd to create environment

4. Create an environment to add image files: run the following 5 commands in sequence on the command line to add.

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

conda config --set show_channel_urls yes

5. After the input is completed in sequence, enter the following instructions (try to be consistent with the python version in step 1, where the python version is python=3.6, the virtual environment name is py36, or you can define it yourself):

conda create -n py36 python=3.6
Now open Anconda and click Environments to find a virtual environment named py36.

 

Note: Next, you can install various scientific computing packages and frameworks (pytorch) in the virtual environment named py36. If there are multiple environments, for example, python3.7 is required, then create a virtual environment of python3.7. With conda management, there will be no version conflicts.

6. To enter the virtual environment, the terminal runs the following command to enter the virtual environment

conda activate py36

In addition, if you want to exit the environment, you are looking at the terminal input:

Conda deactivate
enters the virtual environment as shown in the figure: there will be parentheses (virtual environment name: py36), after entering the virtual environment, you can configure pytorch in an environment where python is 3.6

 

pytorch-CUDA version pip installation

1. Check the CUDA version number supported by the graphics card
, open the control panel, find and open the NVIDIA control panel

Click on the system information in the lower left corner
and click on the third line of the component to see that I can support 11.6

 

2. pytorch query torch-corresponding CUDA version and download it, try to install step 2.2 first, and then install step 2.1 (there is a little secret in it, you can explore this installation sequence!)

2.1 Steps: torch corresponds to CUDA version: Previous PyTorch Versions | PyTorch

The specific procedure is below! ! ! Open cmd and enter the py36 virtual environment: run the following program, the program is as follows, you can also enter the above official website to choose other versions, the mirror installation will be very fast! ! ! The pictures are for step reference

Conda

OSX

# conda

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 -c pytorch

Linux and Windows

# CUDA 9.2

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=9.2 -c pytorch

# CUDA 10.1

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=10.1 -c pytorch

# CUDA 10.2

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=10.2 -c pytorch

# CUDA 11.0

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cudatoolkit=11.0 -c pytorch

# CPU Only

conda install pytorch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0 cpuonly -c pytorch

 

Mirror installation (faster)

Wheel

OSX

pip install torch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0

Linux and Windows

# CUDA 11.0

pip install torch==1.7.0+cu110 torchvision==0.8.0+cu110 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 10.2

pip install torch==1.7.0 torchvision==0.8.0 torchaudio==0.7.0

# CUDA 10.1

pip install torch==1.7.0+cu101 torchvision==0.8.0+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# CUDA 9.2

pip install torch==1.7.0+cu92 torchvision==0.8.0+cu92 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

# CPU only

pip install torch==1.7.0+cpu torchvision==0.8.0+cpu torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

 

2.2 Steps: Go to the CUDA official website to download the corresponding version of CUDA, do not close it and use it later:

CUDA Toolkit Archive | NVIDIA Developer


Here I installed version 10.2

 

 

Select the first download (you can download the basic one, the following two are patches that you can pick up later)
After the download is successful, open the exe file and select the environment installation path (default C drive)

 

Step 3 : After step 2.2 has been installed, it will display successful

4. To test the installation, run the following program:

import torch

x = torch.rand(5, 3)

print(x)

print(torch.cuda.is_available())

 

If the process has ended and the exit code is 0 , the installation is successful! (-1 for unsuccessful)

If you have any questions, you can ask them. I hope you can criticize and correct me if I don’t do well!

おすすめ

転載: blog.csdn.net/m0_46417913/article/details/127466804