简体   繁体   English

无法在虚拟环境中导入'flask_wtf'和'wtforms',即使我已经安装了它们?

[英]Unable to import 'flask_wtf' & 'wtforms' in a virtual env even though I've already pip installed them?

So I'm running a virtual python environment and I was learning flask. 所以我正在运行一个虚拟的python环境,我正在学习烧瓶。 Everything was going good until I got to learning about forms. 在我学习表格之前,一切都很顺利。 I pip installed Flask-WTF in the console (just as I had done with Flask) except when I went to type my code I saw that neither flask_wtf or wtforms could be imported. 我在控制台中安装了Flask-WTF (正如我对Flask所做的那样),除非我输入我的代码,我看到无法导入flask_wtfwtforms Here's my code: 这是我的代码:

from flask_wtf import FlaskForm
from wtforms import BooleanField, PasswordField, StringField, SubmitField
from wtforms.validators import DataRequired

class LoginForm(FlaskForm):
    username = StringField('Username', validators=[DataRequired()])
    password = PasswordField('Password', validators=[DataRequired()])
    remember_me = BooleanField('Remember Me')
    submit = SubmitField('Sign In')

I get errors on lines 1 - 3 for all of the imports. 对于所有导入,我在第1 - 3行出错。 Here's my FlaskProject (top-level) directory: 这是我的FlaskProject (顶级)目录:

Flask Project Top-Level Directory Flask项目顶级目录

Here are all the modules I have installed: 以下是我安装的所有模块:

Flask Project Installed Modules Flask项目安装模块

I'm really not sure what's causing these errors. 我真的不确定是什么导致了这些错误。

EDIT: I also think it's worth noting that I'm not getting errors when importing other modules such as flask. 编辑:我也认为值得注意的是,在导入其他模块(例如烧瓶)时,我没有收到错误。 In case anyone asks, here are the versions of the modules I currently have installed: 如果有人问,这里是我目前安装的模块的版本:

Installed Modules w/ Versions 已安装的模块,带有版本

EDIT2: I'm running Python 3.7 编辑2:我正在运行Python 3.7

EDIT3: These are the only two things I can't seem to import 编辑3:这是我似乎无法导入的两件事

EDIT4: I've actually solved this and I have no idea why but VSCode was marking these items as unable to import when they were, in fact, importing perfectly fine. EDIT4:我实际上已经解决了这个问题,我不知道为什么VSCode将这些项目标记为无法导入,实际上导入完全正常。 Anyways, thanks for the help everyone! 无论如何,感谢大家的帮助!

Maybe you can't see these modules because you've installed them from another virtual environment. 也许您看不到这些模块,因为您已经从其他虚拟环境安装了这些模块。 Can you tell what is the output when you execute the command pip list? 你能告诉执行命令pip list时的输出是什么吗? If there are no modules flask_wtf and wtfforms, you have to activate your virtualenv where are those modules installed. 如果没有模块flask_wtf和wtfforms,则必须激活virtualenv,安装这些模块的位置。 Activate virtualenv using the command: 使用以下命令激活virtualenv:

Windows - source venv/scripts/activate
Linux - source venv/bin/activate

And after that, if you don't have any of these modules already installed, install them using command pip install name_of_module. 之后,如果您尚未安装任何这些模块,请使用命令pip install name_of_module安装它们。

VSCode was marking the imports as an import-error when there was no actual error. 当没有实际错误时,VSCode将import-error标记为import-error错误。 Very weird but everything imported perfectly fine. 非常奇怪,但一切都进口完美。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Vscode 无法导入 flask_wtf 和 wtforms - Vscode not able to import flask_wtf and wtforms ModuleNotFoundError 即使我已经用 pip 安装了它 - ModuleNotFoundError even though I already installed it with pip 导入“flask_wtf”无法解决 - getting Import "flask_wtf" could not be resolved wtforms/flask_wtf 验证器:FileAllowed,不捕获禁止的文件扩展名 - wtforms/flask_wtf validator: FileAllowed, not catching forbidden file extensions 即使通过虚拟环境安装了flask_wtf,我的程序也没有被执行 - my program is not getting executed even after installing flask_wtf through virtual environment 库软件包不在模块PyCharm中,即使我已经安装了它 - Library package not in module PyCharm, even though I've already installed it 我无法从flask_sqlalchemy 和flask_wtf.csrf 导入,即使我为两者都进行了pip 安装。 在我得到一台新电脑之前它就可以工作了 - I can't import from flask_sqlalchemy and from flask_wtf.csrf even though I did pip install for both. It was working before I got a new pc 尝试使用'pip install flask-wtf'安装flask-wtf后没有名为'flask_wtf'的模块 - No module named 'flask_wtf' after trying to install flask-wtf with 'pip install flask-wtf' ModuleNotFoundError: No module named 'flask_wtf' - pip 安装不解决 - ModuleNotFoundError: No module named 'flask_wtf' - pip install not solving 无法将 flask_wtf 导入 Python 3.9 venv - Cannot import flask_wtf into Python 3.9 venv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM