Importing the numpy C-extensions failed. This error can happen for many reasons
问题描述
在anaconda中创建虚拟环境,同一个环境在不同的代码下,一个能运行一个不能运行,不能运行的报错情况如下(因未及时保存,故借网上的同样报错情况的图),从网上找了一下,大致是python版本和numpy版本不匹配的原因造成的,但是我另一个代码正常运行,就挺头大的,所以不想改变环境导致另外一个能运行的运行不了,尝试其他不改变numpy版本的解决方法。
解决方法
将该虚拟环境加入到环境变量中:
以我的虚拟环境为例:
将上述地址添加到环境变量中:
1.搜索框搜索“环境变量”,点击“编辑系统环境变量”:
2.系统变量中点击“Path”后点击“编辑”
3.点击“新建”,将地址复制到地址栏中,点击“确定”,继续点击确定,继续点击确定,一定要连续三次点击确定才能将地址加入到环境变量中!!!(可以重新打开验证一下是否添加成功)
4.之后运行代码,如果不行就重启一下pycharm再运行。
装环境真的好玄学,希望对大家有用。