Pytorch installation process and problem solving

1. Installation steps

  1. Install anaconda, easier
  2. Open Anaconda Prompt (anaconda)
    Insert picture description here
  3. Check the installed python version, here is version 3.7
python --version
  1. Create a house where pytorch resides
conda create -n pytorch python=3.7

Insert picture description here

  1. Activate the house and enter the pytorch configuration environment
conda activate pytorch

Insert picture description here

  1. Command statement to switch to Tsinghua mirror source
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/win-64/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/win-64/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/

conda config --set show_channel_urls yes

(In this step, most of the blogs on the Internet did not write /win-64/ at the end, but I personally think that adding it may be faster)

  1. Tsinghua mirror installation command statement
conda install pytorch torchvision cudatoolkit=10.1

The installation instructions here can be configured on the official website . I chose cuda 10.1. A blog said that if you install below 10, many strange problems may occur. Note that if you don't have a graphics card from Nvidia, install pytorch running on a pure cpu, which is written on the official website. At the same time, you can choose the version of pytorch and the version of torchvision. If you do not choose, the latest version will be downloaded by default.

The above is all the steps to install pytorch, but there will be many strange problems under normal circumstances.

The following are the main installation sources of the three packages. If the network speed is not good enough, you can try to download it locally and then import it (I didn’t try it here, because it was successfully installed afterwards)

三大包的安装源:
pytorch:	 https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64::pytorch-1.7.1-py3.7_cuda101_cudnn7_0			----746.5Mb

mkl-2020.4                 |     hb70f87d_311       172.4 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge::mkl-2020.4-hb70f87d_311

 cudatoolkit-10.1.243       |       h3826478_6       378.0 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/win-64::cudatoolkit-10.1.243-h3826478_6
  1. View Results
    Insert picture description here
  2. If you want to add other packages to the package you just made, you can use the command directly. Here, take pandas as an example:
pip install  pandas

Enter the pytorch directory in Anaconda Prompt (anaconda) and press the above command to
Insert picture description here
install successfully:
Insert picture description here
At the same time, you can also manually manage it directly on anaconda, as shown below
Insert picture description here

Two, test

Check the installed version:

pip list

Insert picture description here
Test code:

//输入
python:
//进入python页面  
//输入:
import torch
//导入torch 没有错误提示说明导入成功
//输入:
torch.cuda.is_available()
//结果是 Ture 表示电脑的GPU可被torch使用

Note that if you are running in pycharm, you need to configure the compiler to execute
Insert picture description here

Three, the solution of some problems

Question 1: About conda’s error resolution: Solving environment: failed with initial frozen solve. Retrying with flexible solve.

To change the channel level:

conda config --set channel_priority flexible
Question 2: Anoconda creates a virtual environment error CondaHTTPError: HTTP 000 CONNECTION FAILED for url

Need to configure 3 paths:
Anocoda configuration environment variables:
at least include Anaconda, Anaconda/Scripts, Anaconda/Library/bin three directories! ! !

E:\Anacoda3\Library\bin
E:\Anacoda3\Scripts
E:\Anacoda3\

(Here E:\Anacoda3\ is the location where the host installs anoconda)

Configuration method:
My computer, properties, advanced system settings, environment variables, system variables, path
Insert picture description here

Question 3: Conda-Downloaded bytes did not match Content-Length problem solution

Insert picture description here
Reference link: https://blog.csdn.net/sinat_36594453/article/details/89599174

Use method two: set the timeout downloaded by conda, and then try again, if the time is not enough, you can set a larger one.

conda config --set remote_read_timeout_secs 600.0
conda config --set remote_read_timeout_secs 10000.0
Question 4: nvidia-smi is invalid

When I want to use nvidia-smi to check the usage of the GPU, I found that C:\Program Files\NVIDIA Corporation\ has no NVSMI folder, so the nvidia-smi.exe file inside is also missing.
Solution:
Link: https://pan.baidu.com/s/1MsLXsC-Z8OyolxWSpxsj9g
Extraction code: wy6l
Unzip NVSMI.zip to C:\Program Files\NVIDIA Corporation\
Insert picture description here
Then add environment variables and
Insert picture description here
enter nvidia-smi Can view
Insert picture description here

问题5:The NVIDIA driver on your system is too old
>>> import torch
>>> torch.cuda.is_available()
E:\anacanda\envs\pytorch\lib\site-packages\torch\cuda\__init__.py:52: UserWarning: CUDA initialization: The NVIDIA driver on your system is too old (found version 9020). Please update your GPU driver by downloading and installing a new version from the URL: http://www.nvidia.com/Download/index.aspx Alternatively, go to: https://pytorch.org to install a PyTorch version that has been compiled with your version of the CUDA driver. (Triggered internally at  ..\c10\cuda\CUDAFunctions.cpp:100.)
  return torch._C._cuda_getDeviceCount() > 0
False

**Solution: **Update the driver
Reference link: https://blog.csdn.net/qq_37163925/article/details/106222654
Insert picture description here

Four, conda instructions

  • Clean up the damaged package:
conda clean --packages --tarballs
  • Update instructions:
conda update --all
  • Mandatory update instructions:
conda update --strict-channel-priority --all
  • Display channel:
conda config --show channels

More conda instructions can be viewed as follows

Guess you like

Origin blog.csdn.net/weixin_44751294/article/details/112558536