问题
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