SoFunction
Updated on 2024-10-29

About PyTorch Environment Configuration and Installation Tutorial (Windows 10)

Beginners in the process of configuring pytorch will always be more or less encountered some problems, at the same time on the Internet about pytorch environment configuration is full of configuration, do not know which should be configured in accordance with the author here to record their own configuration of the whole process of Pytorch in windows 10.

The author's computer environment and installed version: Windows 10 Enterprise + python 3.7.9 + Anaconda3 + GTX 1050 graphics card + pytorch 1.7.1

I. Anaconda Installation

It is recommended (but not required) to install Anaconda here. Because there are times when people may program different versions of python, it is generally recommended for large projects to use one python interpreter (editor) for a project to make it easier to manage, and Anaconda comes in handy to help us do this.

The installation process is very simple, find the corresponding version on the official website and install it, the installation page on the official website is as follows:/products/individual#Downloads

Open Anaconda Prompt in Anaconda in the start menu and (base) appears, which means the installation was successful, as follows:

Anaconda makes it easy to manage all of our our runtime environments as well as the various dependency packages in our environments, and the main page is as follows:

II. Installation of pytorch environment

1. Stay on the Anaconda Prompt page above

importation

conda create -n environment_name python=3.7

As we said before, we need to configure a python editor for each project, so environment_name (change it to the name of the environment you specify yourself, for example, it's called environment_test) is the name of the compilation environment corresponding to this project we configured, which puts in the python editor we specified (here I'm using the python 3.7 for example).

2. The above page appears

Enter y to confirm the installation of the required packages as described above.

The image above appears and the installation of the python editor in the environment is complete.

Now, of course, we're still in the (base) environment, which is the base environment that comes with Anaconda, and we need to jump to the environment_test environment we just created.

3. According to the figure above

Execute conda activate environment_test to jump to the environment_test compilation environment

At this point the environment has changed, type pip list and you can see all the installed packages in the current environment, but there is no pytorch that we want, we need to install it ourselves.

4. pytorch installation

The pytorch installation is very user-friendly, we just need to go to thepytorch official websiteIf you click install, you will see the following interface:

The choices for each are detailed here:

  • ① Pytorch Build: Stable is recommended.
  • ② Your OS: choose according to your own system, here I choose Windows.
  • ③ Package: because we have installed Anaconda, so in the Anaconda Prompt environment we can directly use the Conda way to install, so choose Conda (we actually most commonly used should be pip way, of course, the official website also provides this way, here will not do too much introduction)
  • ④ Language:Python
  • ⑤ CUDA: about how to choose the CUDA version of GPU, open cmd, input nvidia-smi, you can see the CUDA version information, here choose 11.0. (No Nvidia graphics card, or graphics card does not support CUDA or want to use the CPU to run directly choose None on it.)

Note that CUDA9.2 or above version support Driver Version can not be lower than 396.26, it is generally recommended to install before updating the driver of their own graphics card, I just updated yesterday, directly point to update, it is very convenient.

  • ⑥ Run this Command:conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch。

Note: python 3.9 also needs to add -c=conda-forge to the end of the

You can see that it includes pytorch, numpy and some other packages we need, or type y and wait for the installation.

⑦ The installation is complete when done proves that pytorch has been successfully installed. Close the current Anaconda Prompt and reopen it from the Start menu and activate the environment_test environment to open the python editing page in the environment.

Enter import torch and no error is reported, proving that the pytorch package was installed successfully.

Input.is_available(), it shows True, which proves that cuda is installed successfully and you can use GPU to accelerate tensor and network in pytorch. If False, at this time pytorch can only run with CPU.

III. Some problems that may be encountered

The author is documenting some of the problems that occurred during the first installation, here~

1. If the pytorch package installation is not successful, it is recommended to follow the prompts to update the conda version (it is possible that your version of Anaconda is too old, a new installation should not have this problem)

2. 'nvidia-smi' is not an internal or external command: the solution is as follows

  • Typing nvidia-smi directly under windows shows not an internal or external command nor a runnable program.

  • Put C:\Program Files\NVIDIA Corporation\NVSMI
  • Add to path. reopen the cmd window.

  • Okay, it's done.

3. environment to install jupyter, reported react404 error: the solution is as follows

  • [W xx:xx: NotebookApp] 404 GET/static/components/react/ (::1)
  • jupyter notebook won't open
  • Description of the problem
  • When I didn't know that conda had installed some odd packages, I got an error that jupyter wouldn't open The error code is the following.

[W xx:xx: NotebookApp] 404 GET/static/components/react/ (::1)

  • Problem solving
  • Read the article on some blogger on csdn, forgot who it was, just type this under cmd
pip install --user --ignore-installed jupyter
  • Okay, it's done.

4. Step 5 above proves that the pytorch installation was successful, be sure to close the current Anaconda Prompt and re-open the activated environment, because after the new installation the environment is not activated, and some of the dependency packages can not be called at this time.

5. .is_available() shows false for several reasons:

① GPU is not installed correctly, check Task Manager - Performance, whether there is your graphics card underneath.

② CUDA9.2 or above version support Driver Version can not be lower than 396.26, it is generally recommended to update the driver of their graphics card before installation. It is not recommended to go to the NVIDIA website to update, because there are many drivers to check the latest, and you do not know which one will be installed. Directly NVIDIA graphics card settings management software can be installed, see above.

③ The installed CUDA version cannot be higher than the CUDA version supported by the graphics card.

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.