0

This is my first time using anaconda and jupyter notebook. I installed anaconda3, started a new environment, installed pytorch 1.4.0, and then ran jupyter notebook. But when I tried running import torch in the notebook, I got this error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 import torch

File ~\.conda\envs\gan\lib\site-packages\torch\__init__.py:81
     77     sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)
     79 del _dl_flags
---> 81 from torch._C import *
     83 __all__ += [name for name in dir(_C)
     84             if name[0] != '_' and
     85             not name.endswith('Base')]
     87 if platform.system() != 'Windows':

ImportError: DLL load failed while importing _C: The specified module could not be found.

I've tried restarting the kernel, but it didn't work. I also tried downloading and extracting DLL files as mentioned in this post: https://stackoverflow.com/a/51142648/15389253

I ran pip install torch on the command prompt on my computer, and then when I ran python in cmd, I could install and use pytorch without an error. Why does it not work in jupyter notebook?

Update: I ran conda install -c pytorch pytorch=1.4.0 in the gan environment but it said "All requested packages already installed."

  • try running `!pip install torch` within your Jupyter notebook, in a separate cell. – vs07 Jun 26 '23 at 15:46
  • it says "Requirement already satisfied: torch in c:\users\c9812\.conda\envs\gan\lib\site-packages (1.4.0)" but im still getting the same error. – cckdsjo2298e Jun 26 '23 at 15:50

1 Answers1

0
  1. Check if the kernel being used in Jupyter is the same as the one where PyTorch was installed. It seems that you are using the 'gan' env in Jupyter. However, maybe you just installed PyTorch only in the 'basic' environment in the terminal.

  2. Check for version conflicts between PyTorch, CUDA, and cuDNN.

I think the first one should work.

  • Did you try to run torch.cuda.is_available() in gan env terminal? Sorry i cannot comment on yours. – Jiayuan Zhu Jun 26 '23 at 15:15
  • I can't run it because I can't import torch, none of the functions are available. I'll look into the cuda side though, it might be something there. – cckdsjo2298e Jun 26 '23 at 15:40