140

This is the error I am getting and, as far as I can tell, there is nothing useful on the error link to fix this.

RuntimeError: The current Numpy installation ('...\\venv\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime.

See this issue for more information: https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html

I have tried multiple versions of Python (3.8.6 and 3.9.0) and numpy and pandas. I am currently using PyCharm to do all this.

Eric
  • 95,302
  • 53
  • 242
  • 374
Reed Collins
  • 1,403
  • 2
  • 4
  • 6

9 Answers9

193

This error occurs when using python3.9 and numpy1.19.4 So uninstalling numpy1.19.4 and installing 1.19.3 will work.


Edit

As of January 5th 2021 numpy version 1.19.5 is out and appears to solve the problem.

niko
  • 5,253
  • 1
  • 12
  • 32
  • 6
    How to downgrade it using pip? – Shaida Muhammad Nov 05 '20 at 19:47
  • 42
    @ShaidaMuhammad pip install numpy==1.19.3 – mounaim Nov 06 '20 at 16:35
  • 18
    Dammit `numpy`, test before you release please. This isn't beta – NoName Nov 06 '20 at 22:18
  • 4
    I'm using Python 3.7.5 and got this error too (numpy 1.19.4). Downgrading numpy to 1.19.3 indeed prevents the error from happening. – Ralubrusto Nov 13 '20 at 20:45
  • 19
    @NoName: We did test, and the bug is in windows itself. 1.19.3 was an attempt at fixing this by using a different version of OpenBLAS that works around the problem, but that version did not work correctly on linux. – Eric Nov 16 '20 at 09:30
  • I had the same issue with python 3.8 and 'pip install numpy==1.19.3 --upgrade' solved it ! Thanks ! – Ismael EL ATIFI Nov 19 '20 at 14:23
  • Same issue with Python 3.8 – tagoma Dec 05 '20 at 11:23
  • 1
    @Eric While it is clearly a problem with the Windows libraries, this just doesn't seem like a great solution. The link that shows up when the sanity check fails doesn't even provide any workaround for the time being. – natiiix Dec 07 '20 at 14:38
  • 2
    @Eric the silent majority appreciates the incredible work you and all numpy authors are doing and doesn't feel like a simple to google downgrade fix to make numpy work on a broken OS is too much to do once in a decade in return – Bananach Mar 30 '21 at 14:01
57

I am using Python 3.7, anyway the same solution suggested here helped me.

pip install numpy==1.19.3

Actually the link informed https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html shows the given solution. It seems to be a bug in Visual Studio, which remains unsolved up to this date.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Fabio Mendes Soares
  • 1,357
  • 5
  • 20
  • 30
28

Just install numpy==1.19.3 I am using python 3.9

Dipesh Paul
  • 439
  • 4
  • 9
20

As per the discussion on the link you provided, a numpy dev answered:

NumPy has released a bugfix 1.19.3 to work around this issue. The bugfix broke something else on Linux, so we had to revert the fix in release 1.19.4, but you can still install the 1.19.3 via pip install numpy==1.19.3.

So, if you need requirements that work for both Linux and Windows, you'll need to use PEP508:

numpy==1.19.3; platform_system == "Windows"
numpy>=1.19.4; platform_system == "linux"
Pierre.Sassoulas
  • 3,733
  • 3
  • 33
  • 48
12

It's a bug of numpy 1.19.4 that fails with all python versions. Use the previous version to solve the problem, so by terminal:

pip install numpy==1.19.3
Morgana
  • 205
  • 3
  • 5
10

Rolling back to numpy 1.19.3 worked for me on python 3.8.6

5

The workaround is provided in the link mentioned in question.

The developer mattip mentions below in the workaround suggested by him:

  1. Uninstall numpy.( Most probably it's 1.19.4)
  2. pip install numpy==1.19.3

This worked for me.

My configuration:OS-Win10,Anaconda Distribution,python=3.7

Vikram
  • 332
  • 3
  • 16
1

Why hasn't anyone posted the difference between 1.19.3 and 1.19.4.

The problematic numpy init code is:

def _win_os_check():
    """
    Quick Sanity check for Windows OS: look for fmod bug issue 16744.
    """
    try:
        a = arange(13 * 13, dtype= float64).reshape(13, 13)
        a = a % 17  # calls fmod
        linalg.eig(a)
    except Exception:
        msg = ("The current Numpy installation ({!r}) fails to "
                "pass a sanity check due to a bug in the windows runtime. "
                "See this issue for more information: "
                "https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html")
        raise RuntimeError(msg.format(__file__)) from None

if sys.platform == "win32" and sys.maxsize > 2**32:
    _win_os_check()

del _win_os_check

This code section doesn't exist in 1.19.3; that's the only difference.

Avy
  • 45
  • 2
  • 8
    There's another more important difference between the 1.19.3 and 1.19.4 wheels installed by pip - the version of OpenBLAS they are built with. If you remove that code from numpy 1.19.4, then instead of numpy not importing, you'll get a numpy that produces incorrect results and/or crashes randomly. The correct fix is to switch to 1.19.3, which contains a "safe" build of OpenBLAS. – Eric Nov 16 '20 at 09:40
1

I had to follow below steps to fix this error as everyone else has suggested above.

My environment details: Windows 10 64 bit, with Python 3.9.0 installed. I have installed pip 20.3.1

pip uninstall numpy
pip install numpy==1.19.3

I am posting my powershell command line output for your reference(may be useful to someone).

PS C:\Users\XXXX> pip uninstall numpy

Found existing installation: numpy 1.19.4

Uninstalling numpy-1.19.4:

Would remove:

c:\python39\lib\site-packages\numpy-1.19.4.dist-info\*

c:\python39\lib\site-packages\numpy\*

c:\python39\scripts\f2py.exe

Proceed (y/n)? y

Successfully uninstalled numpy-1.19.4

PS C:\Users\XXXX> pip install numpy==1.19.3

Collecting numpy==1.19.3

Downloading numpy-1.19.3-cp39-cp39-win_amd64.whl (13.3 MB)

 |████████████████████████████████| 13.3 MB 6.4 MB/s

Installing collected packages: numpy

Successfully installed numpy-1.19.3

Chinmay T
  • 745
  • 1
  • 9
  • 17