Import error - "module functions cannot set METH_CLASS or METH_STATIC"

Hi!

When I try to import torch, I get the error “module functions cannot set METH_CLASS or METH_STATIC”, the full error is below.

This seems to be an issue a few people encountered last year (ValueError and ImportError occurred when import torch , https://github.com/pytorch/pytorch/issues/2731) and the suggested solution involved reinstalling numpy with some install flags set (although I don’t understand how this fixed the problem). I’ve tried this solution to no avail. I have the latest stable builds of torch and numpy and I’m running python 3.6. Would be very grateful for some assistance, thanks!

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-17-6c0c4fe4210e> in <module>
      1 import numpy as np
----> 2 import torch
      3 import pandas as pd
      4 import matplotlib.pyplot as plt
      5 from sklearn.preprocessing import OneHotEncoder

~/Dev/indiv_project/indiv_project/lib/python3.6/site-packages/torch/__init__.py in <module>
     77 del _dl_flags
     78 
---> 79 from torch._C import *
     80 
     81 __all__ += [name for name in dir(_C)

ValueError: module functions cannot set METH_CLASS or METH_STATIC
2 Likes

I have the same problem on google colab

Did you try to reinstall numpy or check for files in your current working directory using common names (e.g. random.py)?