0

I'm using Jupyterhub, and am running someone else's code that uses pytorch. They include it via import torch, but I get the error "No module named 'torch'". I installed pytorch locally with conda, but still get the same error in Jupyterhub.

What I Want To Know:

For modules like pytorch that aren't part of Jupyterhub out of the box, how do you include them? Do you do it by installing them locally like I did? If so, what should I do differently?

gkeenley
  • 6,088
  • 8
  • 54
  • 129

1 Answers1

0

Create a conda environment for installing pytorch.

conda create -n pytorch_env python=3 ( you can create with any python version )

Activate the environment.

conda activate pytorch_env

Now install PyTorch using:

conda install pytorch-cpu torchvision -c pytorch

To get the installed pytorch in the jupyter notebook, follow the below instructions.

Install the ipykernel :

conda install ipykernel

Follow the command.

ipython kernel install --name pytorch_env --user

Now open the jupyter and select the "pytorch_env" from Kernel option. ( path : jupyter -> kernel -> change kernel -> pytorch_env )

Then import pytorch in jupyter notebook using:

import torch