pytorch

How to Install PyTorch in Jupyter Notebook?

The Jupyter project was created a decade ago to make collaborative work on python projects more accessible for its users. Now, the Jupyter Notebook is an IDE of choice for the PyTorch framework and the development of machine learning models. A popular platform to access the Jupyter IDE is Anaconda which provides a lot of key features and optimizations for data scientists and programmers.

In this blog, the attention will be on how to install PyTorch in a Jupyter Notebook.

How to Install PyTorch in a Jupyter Notebook?

In this tutorial, the “Anaconda” platform will be used for demonstration. The first thing to be done is to add the “Jupyter” notebook and then install PyTorch.

Follow the steps below to learn how to do so:

Step 1: Open the Anaconda Prompt in the Windows OS

Go to the “Start Menu”, type in Anaconda, and click on the “Prompt Window” icon:

Step 2: Install Jupyter in Anaconda

Before PyTorch, the Jupyter notebook needs to be installed into Anaconda:

python -m pip install jupyter

Step 3: Launch the Jupyter Notebook in Anaconda

The next step is to launch the previously installed Jupyter Notebook:

jupyter notebook

Step 4: Install PyTorch in Jupyter

Lastly, use the installation command for PyTorch in the Jupyter Notebook:

pip3 install torch torchvision torchaudio

The output shows that we have installed the PyTorch on Jupyter Notebook:

Pro-Tip

The Jupyter Notebook can also be installed in Google Colab online. Colab provides free GPU access to its users to run their deep learning models without the risk of bottlenecking due to hardware limitations.

Success! We have just shown how to Install PyTorch in a Jupyter Notebook.

Conclusion

Install PyTorch in a Jupyter Notebook by first adding Jupyter to the Anaconda Prompt, then activate the Jupyter Notebook and run the “pip3 install torch torchvision torchaudio” command to install PyTorch. This will install PyTorch and you will be ready to work on machine learning models within the Jupyter IDE. In this blog, we showed how to add Jupyter to Anaconda and then how to install PyTorch within Jupyter.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.