出现错误:即使我已安装flask,在VSCode中“没有名为flask的模块" [英] Getting Error: 'No module named flask' in VSCode even when I have installed flask

查看:124
本文介绍了出现错误:即使我已安装flask,在VSCode中“没有名为flask的模块"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在VSCode中使用Python和Flask调试应用程序.我已经安装了Flask,并且该应用通过cmd运行得很好.但是,当我尝试通过VSCode对其进行调试时,会出现以下错误:

I want to debug an application using Python and Flask in VSCode. I have installed Flask and the app runs perfectly fine through cmd. But, when I try to debug it through VSCode, it gives the following error:

cd 'c:\Users\Aditi\CleanHandymanApp'; 
${env:FLASK_APP}='NewApp'; ${env:PYTHONIOENCODING}='UTF-8'; 
${env:PYTHONUNBUFFERED}='1'; & 'C:\Users\Aditi\envs\CleanHandymanApp\Scripts\python.exe' 
'c:\Users\Aditi\.vscode\extensions\ms-python.python-2018.10.1\pythonFiles\experimental\ptvsd_launcher.py' '--client' '--host' 
'localhost' '--port' '63143' '-m' 'flask' 'run' '--no-debugger' '--no-reload'
No module named flask

能帮我吗?

推荐答案

有时,如果将Flask加载到包含子文件的文件夹中,则可能会出现此错误.例如,如果您将flask与虚拟shell实例一起加载到父文件夹中,但是您正在子文件中运行代码(假设父文件名为crypto_files,而内部文件则是名为blockchain.py的python源代码文件),那么为了使flask正常运行,您必须运行如下文件:

Sometimes you can get this error if you loaded Flask into a folder which has sub-files. For instance, if you loaded flask into the parent folder with the virtual shell instance but you're running your code in the child file (let's say parent is called crypto_files and inside that is a python source code file called blockchain.py ), then in order to get flask to run properly you'd have to run the file like this:

python crypto_files/blockchain.py

python crypto_files/blockchain.py

这使您的机器可以看到Flask在crypto_files中运行,但也可以运行blockchain.py.

This allows your machine to see Flask running inside crypto_files but also run blockchain.py .

或者,您可能只是将Flask重新加载到子文件中... blockchain.py,然后从子文件中运行它.

OR, it's possibly you could just reload Flask into the sub(child)file... blockchain.py and then you'd run it from within the subfile.

这种复杂性主要归因于现代的虚拟实例"和外壳,它们基本上就像在ACTUAL硬盘内部创建虚拟计算机一样.Flask这样做是为了避免在任何地方运行,并且由于Flask是模块化的,因此它允许您的每个项目运行Flask的不同模块化配置,以精确地适合每个项目.另一种选择是可怕的:您必须为每个项目加载最胖的Flask版本和数十个附加组件,因此所有git和所有项目都将拥有大量额外的代码.Flask的核心构造非常小,可以避免此问题(太冗长了!).

This complication is mainly due to modern "virtual instances" and shells which are basically like creating a virtual computer-machine inside your ACTUAL hard machine. Flask does this to avoid running everywhere, and since Flask is modular it allows each of your projects to run different modular configurations of Flask to suit each project precisely. The alternative would be awful: you'd have to load the fattest version of Flask with dozens of add-ons for each project, and so all your git and all your projects would have tons of extra code. Flask is built to be very small at the core to avoid this problem (too verbose!).

这篇关于出现错误:即使我已安装flask,在VSCode中“没有名为flask的模块"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆