Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

multiarray failed to import error

📅 2019-Jul-06 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

Problem

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

Solution

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: