I installed PyTorch locally using pip3. And then I wrote my first PyTorch program that had this import at the top:
import torch.nn as nn.
When I ran the script, that import failed with this error:
Traceback (most recent call last): File "./tmp.py", line 3, in <module> import torch.nn as nn File "/home/ashwin/.local/lib/python3.6/site-packages/torch/__init__.py", line 79, in <module> from torch._C import * ImportError: numpy.core.multiarray failed to import
I have faced this problem many times in different environments. It has always been due to clashes between multiple NumPy libraries installed on the system.
Here are the solutions that worked for me:
pip3 uninstall numpyhad not removed NumPy. I went into
~/.local/lib/python3.6/and manually deleted all NumPy related directories and reinstalled NumPy using pip3.