本文介绍了ModuleNotFoundError:即使存在numpy,Flask应用程序中也不存在名为"numpy"的模块错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个我想在其中使用numpy的flask应用程序.我使用 import numpy as np ,但是当我运行应用程序时出现此错误, ModuleNotFoundError:没有名为"numpy"的模块.我确实在python中安装了numpy,并通过在python cmd中导入numpy对其进行了交叉检查,如下所示:

I'm developing a flask application in which I want to use numpy. I used import numpy as np but when I run the application I get this error, ModuleNotFoundError: No module named 'numpy'. I do have numpy install in python and also cross-checked it with importing numpy in python cmd as below:

C:\Users\Zirak Mistry>python
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>>

在执行命令 import numpy 后没有错误,这意味着numpy已安装在python中并且工作正常.但是,当我将numpy导入我的flask应用程序时,出现了错误.为什么这样?请帮忙.

No error after executing the command import numpy means that numpy is installed in python and is working properly. Yet when I'm importing numpy into my flask application, I'm getting errors. Why so? please help.

推荐答案

运行Flask的Python可能与测试 import numpy 的Python不同,而numpy是安装在错误的Python中.

Probably the Python you are using to run Flask is not the same as the one you tested the import numpy with, and numpy is installed in the wrong Python.

您可以使用 sys.executable 来确定从何处运行Python.在Flask应用程序和cmd中都尝试一下,看看它们是否相同.

You can use sys.executable to determine where you are running Python from. Try both in your Flask app and in cmd to see if they are the same.

如果它们确实相同,则Flask应用也有可能在搜索模块的地方发生了变化.这可以通过编程方式进行更改.如果不在 sys.path 上,则正常的导入机制将找不到它.

If they really are the same, it's also possible that the Flask app has changed where it is searching for modules. This can be changed programmatically. If it's not on sys.path the normal import mechanism won't find it.

这篇关于ModuleNotFoundError:即使存在numpy,Flask应用程序中也不存在名为"numpy"的模块错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:35