ValueError and ImportError occurred when import torch

The following error occurred when I try to run a python script called in the Desktop/math folder, which is a mathematical symbol classifier:

stupid-idiot:math likunshu$ python
ImportError: numpy.core.multiarray failed to import
Traceback (most recent call last):
  File "", line 3, in <module>
    import torch
  File "/Users/likunshu/anaconda/lib/python3.6/site-packages/torch/", line 53, in <module>
    from torch._C import *
ValueError: module functions cannot set METH_CLASS or METH_STATIC

Then in the same shell, I typed ipython, and successfully import torch like this:

In [1]: import torch

In [2]: torch.__path__
Out[2]: ['/Users/likunshu/anaconda/lib/python3.6/site-packages/torch']

I’ve googled it on the Internet and tried many solutions but nothing worked. Does anyone have some ideas about how to solve this problem?
My Python version is 3.6.1 and Anaconda version is 4.4.0

1 Like

Remove the old numpy and run the following code.
pip install -U numpy


You’re exactly right! Thanks for your answer~, help me a lot!

Yes this helps! Thanks a lot~