This article mainly records how to install pytorch on the computer and configure the relevant environment in vscode, as well as some problems encountered during the configuration process. Without further ado, let's start now.
1. Install VS Code
Go to Microsoft's official website to download vs code , select the community version, and install it by default
2. Install Anaconda
Go to Anaconda official website to download an installation package, pay attention to the Python version of your computer, you can use it in the console
python -v
Check your version number. Mine is 3.9 so download the latest directly
3. Download CUDA tools
1. Determine the CUDA version supported by your graphics card
Find " System Information " in the lower left corner of the NVIDIA control panel , and find the supported CUDA version in " Components "
Go to the CUDA download page and select the appropriate CUDA version for your computer to download. If you can't find the corresponding version on the default page, you can find the historical version below.
You can choose to customize the installation during installation to avoid installing the family bucket (in fact, it has already been installed), I choose to uncheck VS Integration, and install everything else. Of course, if the memory of the C drive is not enough, you can also specify another drive, and it will have no effect.
After the installation is complete, the environment will be automatically deployed. If there is no automatic deployment environment, you can check how to deploy it on Baidu.
Then use the code to verify the environment in CMD
nvcc --version
2. Download the CUDnn module
CUDnn is used for neural network computing. The download address is CUDnn download . After completing the registration, select the corresponding CUDA version to download. After downloading, decompress the three folders in the compressed package to the place where CUDA was installed before.
For details, please refer to this blog post CUDA installation tutorial
3. Install PyTorch
Go to the official website https://pytorch.org/ , choose your corresponding situation, and get an installation password
Paste this sentence directly in the Anaconda console and wait for the installation to succeed. If done, it means the installation is successful. Some domestic networks may experience slow download/installation failure. You can refer to How to solve the problem of slow download of pytorch and replace the Tsinghua mirror to solve it.
4. Configure VSCode
1. Install the plugin
It is recommended to install the following plugins
2. Configure the interpreter
Select the environment in the lower right corner of vscode
Select the pytorch interpreter, if not, you can find it in the installation path
If you make an error, you can try to configure the environment (I haven’t configured it anyway, you can search on Baidu if necessary)
3. A little problem
I tested after completing the configuration and found that the version number of numpy is inconsistent with the version number of pytorch, you can use
pip list
or
conda list
To verify the version number, if it is wrong, remember the correct version number that the compiler prompts you, and run the following code in the Anaconda console to solve the problem
pip uninstall numpy
pip install numpy==1.18.2 --替换为你需要的版本
finally run perfectly