简体   繁体   中英

How to get pytorch to work in Jupyterhub?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM