0

On my conda environment importing torch from command line Python and from a jupyter notebook yields two different results.

Command line Python:

$ source activate GNN
(GNN) $ python
>>> import torch
>>> print(torch.__file__)
/home/riccardo/.local/lib/python3.7/site-packages/torch/__init__.py
>>> print(torch.__version__)
0.4.1

Jupyter:

(GNN) $ jupyter notebook --no-browser --port=8890

import torch

print(torch.__file__)
/home/riccardo/.local/lib/python3.6/site-packages/torch/__init__.py

print(torch.__version__)
1.2.0+cu92

I tried the steps suggested in Conda environments not showing up in Jupyter Notebook

$ conda install ipykernel
$ source activate GNN
(GNN) $ python -m ipykernel install --user --name GNN --display-name "Python (GNN)"
Installed kernelspec GNN in /home/riccardo/.local/share/jupyter/kernels/gnn

but that did not solve the problem.

den3b
  • 13
  • 4
  • 2
    Please add for python and jupyter the output of the following commands to your question: `print(torch.__file__)` and `print(sys.path)`. – cronoik Oct 09 '19 at 11:27
  • 2
    Possible duplicate of [Conda environments not showing up in Jupyter Notebook](https://stackoverflow.com/questions/39604271/conda-environments-not-showing-up-in-jupyter-notebook) – merv Oct 09 '19 at 21:30

1 Answers1

1

You need to sort of make the Anaconda environment recognized in Jupyter using

conda activate myenv
conda install -n myenv ipykernel
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"

Replace myenv with the name of your environment. Later on, in your Jupyter Notebook, in the Select Kernel option, you will see this Python (myenv) option.

merv
  • 67,214
  • 13
  • 180
  • 245
akshayk07
  • 2,092
  • 1
  • 20
  • 32
  • If this answer helped, then you can click the green tick beside the answer to mark this question answered. Also upvote :D. – akshayk07 Oct 16 '19 at 17:05
  • 1
    Thanks for pointing that out. I did upvote, but you can't see it as I have less than 15 reputation (just created account). Cheers – den3b Oct 20 '19 at 23:06
  • akshayk07 I've installed pytorch locally using conda, but want to be able to use it on Jupyterhub. Should your solution work for this? I don't want to try it in case it crashes something. – gkeenley Nov 19 '19 at 17:03