How to Install Pytorch using Conda

How to Install Pytorch using Conda

Pytorch is one of the most popular frameworks that are used for pytorch development. This article details the steps required to install Pytorch on Windows using Conda. If you don't already have conda installed, follow this blog for instructions on how to install it.

Step 1: Create a new conda environment.

Technically, creation of a new environment is not required for the installation of Pytorch. However, it is recommended to do so to avoid potentially breaking already existing packages on that environment. If there are existing dependencies on specific version of a package, and Pytorch installation ends up updating the package, it might result into stability issues.

To create a new environment, open anaconda prompt and run the command conda create --name torch python=3.9. Replace 'torch' with what you want your environment name to be. This command creates a new virtual environment named 'torch' and installs python 3.9 version. The execution of the command should reveal a similar output to the one shown in Figure 1. create_new_env.pngFigure 1: Command to create a new conda environment.

Step 2: Install Pytorch

Head over to the official site and select the preferred version of pytorch that you wish to install. After selecting you should see a generated command that you run in the anaconda prompt. An example is shown in Figure 2, which shows the generated command for installing pytorch with gpu support. pytorch_command.pngFigure 2: Selection of Pytorch version. site

Figure 3 displays the terminal output after running the installation command. conda_install_pytorch.pngFigure 3: Terminal output of pytorch installation

Step 3: Verification

After the installation process, make sure to verify that the packages were installed correctly. Figure 4 demonstrates an example of the verification steps mentioned on the official site. pytorch_verification.png Figure 4: Pytorch verification process

If you don't have a Nvidia Gpu for your computer or laptop, the second command which states torch.cuda.is_available() will return false.

Conclusion

This post articulated a 3-step process for installing Pytorch. If you are new to the field of AI development and were looking for a installation guide, I hope this post helped. If you liked this article, feel free to react or leave a comment. Feedback is always appreciated. Thanks for reading.