1

I did install pytorch on my M1 MacBook. But if I try to import it, I keep getting an error saying No module named 'torch'

Here's several ways I tried: (method #1 and #2 are from Pytorch official website)

#1

conda install pytorch torchvision torchaudio -c pytorch

#2

conda install pytorch torchvision torchaudio -c pytorch-nightly

#3

this medium article

And If I try to run those command again, it say it's already installed, but if i run import torch, it say No module named 'torch' in Jupyter noteboook.

And in terminal if I type python then import torch works but if if type python3 then import torch does not work.

Why I'm getting this error, and how can fix this issue?

Seungjun
  • 874
  • 9
  • 21
  • If import works in the terminal but not in side the notebook, then the environment the notebook kernel is running in is not the same as in the terminal. This [here](https://towardsdatascience.com/get-your-conda-environment-to-show-in-jupyter-notebooks-the-easy-way-17010b76e874) may help. Do you see Python 3 as the version when you enter `python` in your terminal? If so, you are using Python 3. Depending on how you set things up, it may not be important for `python3`-associated things to work. The `python3`-stuff was only a necessary thing during when people had Python 2 around, too. – Wayne Feb 09 '23 at 21:10
  • Also see [here](https://github.com/jupyter/notebook/issues/3311#issuecomment-406740348) and the second second section [here](https://stackoverflow.com/a/67198468/8508004). – Wayne Feb 09 '23 at 21:11
  • This might also be an arm64 vs x86_64 issue. macOS no longer ships with python at all - Xcode command line tools provide `python3`, but `python` you must've gotten elsewhere. – Siguza Feb 25 '23 at 20:41

0 Answers0