[Pytorch] Install and create the GPU version of Pytorch in Anaconda under Win10 (the test is effective, and the steps are clear)

Anaconda installation

GPU版Pytorch

anaconda prompt

Find the anaconda prompt from the start, click to open the
Insert picture description here
command line input: conda create --name pytorch_gpu_cuda80 python=3.6
python_gpu_cuda80 is the virtual environment name under anaconda, yes 自定义, (because I installed cuda8.0), python=3.6 is the option to install python version.
Choose y to proceed, press Enter , and wait for the relevant package to download, you can see that after the installation is complete, the message prompt is as follows, indicating success:
Insert picture description here
If you want to enable the created environment, enter the command

conda activate pytorch_gpu_cuda80 , here enter the name of the virtual environment created by yourself

To close the environment, enter the command

conda deactivate
now enters the created virtual environment
Insert picture description here

Install Pytorch

Before installation, you need to determine the CUDA version corresponding to your computer's graphics card:
1) win+R, enter cmd to open the command window, enter nvidia-smi, check the graphics card information, you can see that my computer driver Version是369.30
Insert picture description here
generally has different versions CUDA requires different NVIDIA driver versions, and the graphics card driver version must not be lower than the installed version of CUDA. The specific comparison is as follows: According to the
Insert picture description here
above table, it can be found that the computer's corresponding CUDA is 8.0. 2) Open the pytorch official website , select as shown below, and copy the displayed content (marked with a red box in the figure below) , namely: conda install pytorch torchvision cudatoolkit=10.0 -c pytorch At this time, replace 10.0 with the CUDA version determined in the first step (If your computer can install 10.0, skip this step). If my computer supports CUDA8.0, then my command is conda install pytorch torchvision cudatoolkit=8.0 -c pytorch. After confirming the command, don’t worry about installing it. Change the download source at the time, otherwise it is easy to report an error during the download process. 3) Change the download source and change to the Tsinghua University mirror image. In Enter the following command:这一步根据自己电脑的driver Version确定对应的CUDA版本。

Insert picture description here




虚拟环境命令行

# 添加Anaconda的清华镜像
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/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
# 设置搜索时显示通道地址
conda config --set show_channel_urls yes  

As shown below
Insert picture description here

Because it has been replaced before, executing the command again will prompt "updated". If it has not been added before, no information will appear.

4) Start downloading. Input:
conda install pytorch torchvision cudatoolkit=XX.X
XX.X input your own CUDA version number, pay attention to remove the following -c pytorch, or use the default source download.
Insert picture description here
Proceed select y, waiting to download
Insert picture description here

Note: During the download process, the download may be interrupted or failed. This is a normal phenomenon. If the download fails, use the original command to re-download, but when re-downloading, note that it will not continue to download. When downloading, pay attention to the prompt information. If there is a warning, pay special attention. It may prompt. The folder where the download was interrupted needs to be deleted, so we need to delete the file it prompts according to the path information it prompts, or download the file again Will cause failure. During the re-downloading process, it may fail many times. Please be patient. I re-downloaded more than 10 times before the download is complete. If Tsinghua source fails to download multiple times, you can try to add back the previously removed "-c pytorch" command Download again and try again and again. I wish you a successful download.

5) Test
Insert picture description here
returns True, indicating that the installation is successful. If it returns False, it means that the cuda version number of the system is inconsistent with the selected cuda version, and the cuda version needs to be updated. The specific update operation is as follows:
right-click-my computer-management-device manager, find the display adapter, select NVIDIA, right-click- Update the driver, it will update to the latest version, just restart the computer.

Use your own virtual environment in jupyternotebook

1. Activate the virtual environment:

conda activate environment name

2. Install ipykernel in the virtual environment (remember that this step is performed in the corresponding virtual environment):

pip install ipykernel

Use ipykernel to generate the kernel of the virtual environment (this step is also carried out in the virtual environment)

python -m ipykernel install --user --name environment name

3. After the configuration is complete, restart or refresh jupyternotebook, and click new to see the added environment.
At the same time, if there is a problem that there is no corresponding library during the programming process, you can directly pip install XX in the virtual environment.

Guess you like

Origin blog.csdn.net/qq_36477513/article/details/114997129