Search code examples
pythonpytorchtorch

How to solve the ValueError importing torch in python


After installing pytorch package, I have tried to import pytorch with

import torch

but got the error

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "c:\users\user\appdata\local\programs\python\python38\lib\site-packages\torch\__init__.py", line 190, in <module>
    from torch._C import *
ValueError: module functions cannot set METH_CLASS or METH_STATIC

from searching, I have read that this could be about numpy. So I have tried uninstalling and installing with those

pip uninstall numpy
pip install numpy -I
pip install numpy -U

It didn't work.

I would be happy to hear from you if you have any idea why such an error occurs and how to correct it?

in case needed: Python version 3.8.6 , torch version 1.7.0 , numpy version 1.19.4


Solution

  • The latest version of numpy for the moment is 1.19.4

    I have uninstalled numpy and installed 1.19.3 version. After a complete restart of the system. The error does not show anymore. Thanks.