Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named 'torch' #4629

Open
jonanem opened this issue May 14, 2019 · 11 comments
Open

No module named 'torch' #4629

jonanem opened this issue May 14, 2019 · 11 comments

Comments

@jonanem
Copy link

jonanem commented May 14, 2019

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

@markfsousa
Copy link

markfsousa commented Aug 4, 2019

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.

@markfsousa
Copy link

markfsousa commented Aug 4, 2019

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

@dps42
Copy link

dps42 commented Nov 7, 2019

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:

  1. On the top of the Jupyter window, click the "Kernel" drop-down menu.
  2. 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.

@saraXX
Copy link

saraXX commented Jun 13, 2020

if nothing work with you try to install Jupiter notebook from anaconda navigator
it's the only way it works with me

@Raunaque97
Copy link

https://janakiev.com/blog/jupyter-virtual-envs/

This fixed my issue. If it helps anyone

@hj0921
Copy link

hj0921 commented Dec 28, 2020

I solved this issue by installing Jupyter notebook in current environment.

@makwadajp
Copy link

makwadajp commented Mar 29, 2021

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

@malodhi
Copy link

malodhi commented Apr 13, 2021

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 !!!

@jonathonyan
Copy link

When i using conda install jupyter notebook I got 500 : Internal Server Error when opening my jupyter notebook

@AkagawaTsurunaki
Copy link

Don't forget to restart your IDE and server after you installed jupyter and notebook.

@jazelly
Copy link

jazelly commented Apr 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests