I'm getting the following error when trying to import torch
in Jupyter:
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-10-39178> in <module>
1
----> 2 import torch
~/jupyter_py3/lib/python3.6/site-packages/torch/__init__.py in <module>
84 from torch._C import *
85
---> 86 __all__ += [name for name in dir(_C)
87 if name[0] != '_' and
88 not name.endswith('Base')]
NameError: name '_C' is not defined
88 not name.endswith('Base')]
NameError: name '_C' is not defined
Cython
is already installed, in case you may be wondering.
Any idea how to fix this?
UPDATE:
Three years later, I'm getting the same error when attempting to import torch
in Python 3.8.0!
running it from an empty dir makes it go passed this issue. i.e. try the following
mkdir empty_dir && cd empty_dir && python -c 'import torch'
source: answer
Also, I just wan to put it out there that the root cause of this issue for me when importing torch was a broken numpy installation. The thing that ended up solving the entirety of the issue was a simple pip install numpy==1.23.2