Command line python and jupyter notebooks use two different versions of torch

淺唱寂寞╮ 提交于 2020-01-25 07:53:27

问题


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.


回答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.



来源:https://stackoverflow.com/questions/58301581/command-line-python-and-jupyter-notebooks-use-two-different-versions-of-torch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!