无论我做什么,我都不能进口flask_wtf,或者它的任何变体--烧瓶-WTF、flask_WTF、烧瓶-WTF等等。我的连接器认不出它(VSCode中的幽门)--给了我错误:
Import "flask_wtf" could not be resolvedPylancereportMissingImports
当我试图运行代码时,我得到:
Traceback (most recent call last):
File "c:\Users\btaylor\repots\brannen\digitalocean\flask_app\forms.py", line 1, in <module>
from flask_wtf import Flaskform
ModuleNotFoundError: No module named 'flask_wtf'
操作系统为Windows10.1.66.1 VSCode
代码:
from flask_wtf import Flaskform
from wtforms import (StringField, TextAreaField, IntegerField, BooleanField,
RadioField)
from wtforms.validators import InputRequired, Length
class CourseForm(FlaskForm):
title = StringField('Title', validators=[InputRequired(),
Length(min=10, max=100)])
description = TextAreaField('Course Description',
validators=[InputRequired(),
Length(max=200)])
price = IntegerField('Price', validators=[InputRequired()])
level = RadioField('Level',
choices=['Beginner', 'Intermediate', 'Advanced'],
validators=[InputRequired()])
available = BooleanField('Available', default='checked')
我构建了一个新的目录,pip卸载了烧瓶,创建了venv,激活,pip在这个站点上安装了特定的版本:数字海洋.如何用水瓶使用和验证Web表单-WTF:https://www.digitalocean.com/community/tutorials/how-to-use-and-validate-web-forms-with-flask-wtf,并将它们的代码复制到.py文件中。
我安装库的步骤。
单击8.1.2 colorama 0.4.4瓶2.0.2瓶-WTF 1.0.0它危险的2.1.2 Jinja2 3.1.1 MarkupSafe 2.1.1 pip 22.0.4 setuptools 58.1.0 Werkzeug 2.1.1 WTForms 3.0.1
pip冻结显示:
(venv) PS C:\Users\btaylor\repots\brannen\digitalocean> pip freeze
click==8.1.2
colorama==0.4.4
Flask==2.0.2
Flask-WTF==1.0.0
itsdangerous==2.1.2
Jinja2==3.1.1
MarkupSafe==2.1.1
Werkzeug==2.1.1
WTForms==3.0.1
文件夹结构的剪短
发布于 2022-04-28 12:16:13
我想通了。VSCode正在运行Global。但是,如果我在文件夹中输入cli IDE,它将在虚拟环境中运行Python的本地安装。
我在venv\脚本文件夹中找到了python可执行文件。在VSCode中,输入(Windows),选择Python解释器,选择我所在的工作区,“在工作区级别选择”,然后输入到..venv\Scripts\Python.exe的路径。
一旦VSCode被设置为在虚拟环境中运行Python.exe,那么Python就会看到安装在venv中的附加模块。
https://stackoverflow.com/questions/71834509
复制相似问题