notebook
notebook copied to clipboard
No module named 'torch'
I have installed pytorch in virtual environment. When I am trying to execute import torch from Jupyter notebook I am getting error as below.
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-10-eb42ca6e4af3> in <module>
----> 1 import torch
ModuleNotFoundError: No module named 'torch'
But when I am running the same in Using Anaconda command prompt, import torch is successful. I am running Jupyter in windows 64 Anaconda environment
I have the same issue. I've seen this (issues/4827), which is related to the missing lib mkl. But, in my case, I have mkl-2019.4 and it still doesn't work. What is awkward is that this import works fine in spyder, the problem is only in jupyter notebook.
It turns out that the version mkl-2019.4 doesn't really work. I have installed the 2018 and it's fine now.
conda install mkl=2018
I had the same issue. 'import torch' worked on the terminal but it didn't work on the Jupyter. First, on the Jupyter, try to type and see the output of:
print(sys.executable)
I found that the location of the executable was from a different conda environment. What finally worked for me was:
- On the top of the Jupyter window, click the "Kernel" drop-down menu.
- Move the mouse over "Change kernel". Then, I could see a list of different Python conda environments. I noticed that the one that was selected was for Tensorflow. I changed the kernel to
Python [conda env: XXX]
where XXX is whatever the name of the conda environment where Pytorch was set up.
At least it worked for me after hours of frustrating moment. Hope it helps.
if nothing work with you try to install Jupiter notebook from anaconda navigator it's the only way it works with me
https://janakiev.com/blog/jupyter-virtual-envs/
This fixed my issue. If it helps anyone
I solved this issue by installing Jupyter notebook in current environment.
I had the same issue reported by dps42:
'import torch' worked on the terminal but it didn't work on the Jupyter.
for me, calling conda install jupyter notebook worked as mentioned in stackoverflow: Pytorch module error in Jupyter Notebook
I had similar problem: torch being imported in terminal but not in same environments jupyter notebook.
I first got, print(sys.executable), in root directory.
To solve:
I install jupyter notebook in the virutal environment. Later torch was being imported into jupyter notebook. The print(sys.executable), now gave the location of file in conda virtual environment.
Thanks all !!!
When i using conda install jupyter notebook I got 500 : Internal Server Error when opening my jupyter notebook
Don't forget to restart your IDE and server after you installed jupyter and notebook.
conda install jupyter notebook fixed my issue. I believe the jupyter was pointing to the one downloaded from pip. Installing it from conda should override this