ModuleNotFoundError: No module named 'numpy' error in Flask app even if numpy present.

醉酒当歌 提交于 2021-01-07 01:07:37

问题


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
>>>

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.


回答1:


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.

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.

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.



来源:https://stackoverflow.com/questions/53955580/modulenotfounderror-no-module-named-numpy-error-in-flask-app-even-if-numpy-pr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!