Install Pytorch and configure Pycharm

PyTorch is a Torch-based Python open source machine learning library for applications such as natural language processing. It is mainly developed by Facebookd's artificial intelligence team. It not only enables powerful GPU acceleration, but also supports dynamic neural networks, which is not supported by many mainstream frameworks such as TensorFlow. This article details the steps to install Pytorch and Pycharm configuration.

After installing Anaconda, use the command line mode
to create an environment

conda create -n pytorch python=3.7

However, it always reported that the https connection could not be connected
Insert image description here
. I tried many methods but could not solve it. Finally, I used this method to solve the problem.
The original address https://github.com/conda/conda/issues/8273
Insert image description here
is to the effect: conda found the wrong address of openssl . conda looks for the openssl dll file in the Anaconda\DLLs directory , but the actual required dll is in the Anaconda3\library\bin directory. So you only need to copy these two files to Anaconda\DLLs.

Follow the prompts to copy the two dlls to the specified directory.
D:\tools\anaconda\Library\bin —>D:\tools\anaconda\DLLs
Insert image description here
Create the environment again conda create -n pytorch python=3.7 -n The following is the name of the environment. To customize the
Insert image description hereselection,
use the command, conda env list to view Environment
Insert image description here
Then we enter the command to enter the pytorch environment

conda activate pytorch

Insert image description here
In order to improve download speed, use domestic download sources

Tsinghua source:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

Dayuan of Science and Technology of China

conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes

After entering each line of command, use the command to check whether the new download source takes effect.

conda config --show-source

Insert image description here
Next install Pytorch and find the version that suits you on the official website, https://pytorch.org/get-started/previous-versions/

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch

It takes a long time. When this page finally appears, it means the installation is complete.
Insert image description here
Exit the pytorch environment.

conda deactivate

View environmental information

conda info -e

Insert image description here
Verify that pytorch is installed successfully.
Enter the pytorch environment
Insert image description here
and import torch.

torch.cuda.is_available() verifies whether cuda is running normally. I have not installed cuda, so this is False
Insert image description here
to uninstall the pytorch environment.

conda remove -n pytorch --all

Configure pycharm
Insert image description here
Insert image description here

Install ipython and enter the environment

conda install nb_conda

After installation enter the command

jupyter notebook

Jupyter will pop up automatically. You can also enter the following code inside to verify whether the torch is successfully installed and whether the GPU can be used in this environment.

import torch
torch.cuda.is_available() 

torch.cuda.is_available() displays False.
Check pytorch1.11 to see how much the driver version needs to be.
If our driver version is smaller than this value, we need to upgrade the driver.

nvidia-smi

There are two ways: one is to upgrade through various software managers, the other is to find the corresponding driver through https://www.nvidia.cm, download it, install it directly, and then come back to see if the driver version is greater than

Guess you like

Origin blog.csdn.net/qq_30353203/article/details/131583749