4 Steps to install Anaconda and PyTorch on Windows 10

Chu-Tak Li
Analytics Vidhya
Published in
4 min readNov 19, 2020

Hi guys:) Today, I would like to share how to install Anaconda and PyTorch (with/without GPU) in Windows 10 such that you can run different deep learning-based applications. Let’s start!

Image by the author. The image of the tiger is captured from [here] (CC0 Public Domain)

1. Install Anaconda

The first step is to install Anaconda such that you can create different environments for different applications. Note the different applications may require different libraries. For example, some may require OpenCV 3 and some require OpenCV 4. So, it is better to create different environments for different applications.

Please click [here] to go to the official website of Anaconda. Then click “Download” as shown below.

Figure 1. Official website of Anaconda. Captured from [here] by author

Select the installer based on your OS. Assume that your OS is Windows 10 64-Bit. Figure 2 is an example of selecting the installer.

Figure 2. Anaconda Installers selection page from the official website of Anaconda. Captured from [here] by author

Start to download the EXE of the installer and then follow the instructions to install Anaconda to your OS. Detailed instructions with screen captures are available at [here].

2. Install CUDA Toolkit (if you have GPU(s))

If you have GPU(s) on your computer and you want to use GPU(s) to speed up your applications, you have to install CUDA Toolkit. Please download CUDA Toolkit [here].

Select your Operating System, Architecture, Version, and Installer Type as shown below.

Figure 3. Select Installer for CUDA Toolkit 11.1. Captured from [here] by author

Click the “Download” button as shown in Figure 3 above and then install the CUDA Toolkit. The newest version of CUDA Toolkit is 11.1 at the time of writing this installation guide. Note that you have to check which GPU you are using and which version of CUDA Toolkit is applicable.

3. Create Conda environment for PyTorch

If you have finished Step 1 and 2, you have successfully installed Anaconda and CUDA Toolkit to your OS.

Please open your Command Prompt by searching ‘cmd’ as shown below.

Figure 4. Searching for cmd. Image by author

Then, type the following line to your cmd

conda create -n ailab python=3.7

By typing this line, you are creating a Conda environment called ‘ailab’

Figure 5. Example of typing the line to create a Conda environment. Image by author

Figure 5 shows an example of typing the above line to the cmd.

You should see the following, please type ‘y’ to continue the creation. Note that you may need to wait for a few minutes.

Figure 6. Example of creating Conda environment (type ‘y’ to continue). Image by author

After finishing the creation, type the following line to activate your conda environment ‘ailab’

conda activate ailab

You should see something like the below.

Figure 7. Example of activating a Conda environment ‘ailab’. Image by author

Now, you are inside your Conda environment ‘ailab’. You can install the necessary libraries for deep learning-based applications.

Type the following lines one-by-one (# represents the explanation for the code below),

# install PyTorch and Torchvision libraries with CUDA Toolkit version 11

conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch

# install Pandas library for handling dataframe, csv data, etc.

pip install pandas

# install matplotlib library for plotting training and testing curves

pip install matplotlib

# install OpenCV library for image pre/post-processing

conda install -c conda-forge opencv

# install Pillow library for reading and writing images

conda install -c anaconda pillow

4. Verify your installation

Here, we are going to verify the installation.

To check the installation of PyTorch with/without GPU(s) available, type the following three lines:

python

import torch

torch.cuda.is_available()

If GPU(s) is/are available for the PyTorch platform, it returns True else False as shown below.

Figure 8. Example of verifying PyTorch with/without GPU(s). Image by author

In the above case, we do not have a GPU, hence it returns False.

Congrats

Now, you can try to run different deep learning-based applications on your computer. You may try a simple direct use of a pre-trained AlexNet for Image Classification [here]. Hope you guys find this post useful:)

Thanks for reading my post. If you have any questions, please feel free to send me an email or leave comments here. I am happy to hear from you and any suggestions are welcome. Hope to see you next time! :)

--

--

Chu-Tak Li
Analytics Vidhya

DO IT FIRST. ONLY U CAN DEFINE YOURSELF. I have started my PhD journey accidentally. To know more about me at: https://chutakcode.wixsite.com/website