问题现象
在Visual Studio Code 中编写Python时,调用numpy出现RuntimeError错误
Exception has occurred: RuntimeError The current Numpy installation ('C:\Users\Username\AppData\Local\Programs\Python\Python39\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 File "C:\Users\Username\Desktop\just_a_testing.py", line 1, in import numpy as np
原因
查询知是本机的python 3.7.x and numpy 1.19.4版本兼容性问题,解决方法是卸载当前版本,尝试安装numpy 1.19.3
解决方法
启动cmd进入python的安装目录下的scripts文件夹,这里的路径我使用的是安装vs2019时附带的版本。
cd C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\Scripts
如果是使用单独下载的安装包安装的python,则可能在如下的目录中:
C:\Program Files (x86)\python37\Shared\Python37_64\Scripts
使用命令卸载numpy模块
pip.exe uninstall numpy
这里命令行给我提示
Successfully uninstalled numpy-1.19.4
又出现了一些错误提示,不过我没理它们。
重新安装numpy 1.19.3模块
pip.exe install numpy==1.19.3
然后重新跑代码,可见问题解决。