ModuleNotFoundError:没有名为"flask_wtf"的模块 [英] ModuleNotFoundError: No module named 'flask_wtf'

查看:1495
本文介绍了ModuleNotFoundError:没有名为"flask_wtf"的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里找到了类似的问题,但是找不到具体的解决方案. 我有一个已激活并正在运行的虚拟环境,并且在其中安装了flask-wtf模块,如下所示:

I've found already similar questions here, but could not find specific solution. I've got virtual environment, which is activated and running, and within it I've installed flask-wtf module, as:

pip install flask-wtf

然后,有一个名为"test.py"的脚本,该脚本从flask_wtf中导入导入FlaskForm ->,并从终端启动时为

Then, there is script called "test.py", which contiains from flask_wtf import FlaskForm -> and when it is started from terminal as

python test.py

引发错误,因为

    from flask_wtf import FlaskForm
ModuleNotFoundError: No module named 'flask_wtf'

命令

which flask_wtf

不返回任何内容.但是,我可以在flaskEnv/lib/python3.6/site-packages文件夹中看到flask_wtf文件夹(其中flaskEnv-是虚拟环境的目录).

returns nothing. But, I could see flask_wtf folder in flaskEnv/lib/python3.6/site-packages folder (where flaskEnv - is directory for virtual environment).

按照我在网站上找到的建议,以

Following the advise, which I've found here on website, running script as

/home/kosist/Documents/Environments/flaskEnv/bin/python test.py

正常工作-脚本执行无误. 但是-为什么会这样呢?我不想一直输入python的完整路径,而且不希望输入命令

works just fine - script is executed without error. But - why it happens like this? I don't want to enter all the time full path to python, and moreover, command

which python

返回以下内容:

/home/kosist/Documents/Environments/flaskEnv/bin/python

因此调用 python 已经引用了该路径!

so calling python already refers to that path!

如果通过以下方式全局安装flask-wtf模块,脚本也可以工作

Also, script works, if flask-wtf module is installed globally, via

sudo pip install flask-wtf

然后我可以以

python test.py

一切正常.

请有人帮忙解释一下,怎么回事,以及如何解决?因为担心,我缺少从virtualenv调用模块的一些简单要点,而且任何可能安装的模块都可能发生类似的情况.

Could someone, please, help and explain, what is going on, and how to fix it? Because I'm afraid, that I'm missing some simple key point about calling modules from virtualenv, and similar situation could happen to any of the possible installed modules.

推荐答案

最后,找到原因-我忘了,我已经在〜/.bash_aliases文件中为python3.6指定了别名.大小写命令

Finally, the reason was found - I've forgotten, that I had specified alias to python3.6 in ~/.bash_aliases file... So in this case command

which python

返回虚拟环境python的路径,但调用

returned path to virtual environment python, but calling of

python

称为python3.6,已全局安装... 删除〜/.bash_aliases文件后,一切正常.

called python3.6, which is installed globally... After ~/.bash_aliases file was removed, everything works.

这篇关于ModuleNotFoundError:没有名为"flask_wtf"的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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