python - 未找到模块错误:未找到烧瓶模块
问题描述
我只是在 Udemy 上上 Python 课程。这是程序的后端部分,在 Visual Studio 代码的虚拟环境中运行。
from flask import Flask, render_template, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI']='postgresql://postgres:********@localhost/height-email_collector'
db = SQLAlchemy(app)
class Data(db.Model):
__tablename__ ="data"
id =db.Column(db.Integer, primary_key=True)
email_ =db.Column(db.String(120), unique=True)
height_ =db.Column(db.Integer)
def __init__(self, email_,height_):
self.email_ = email_
self.height_ = height_
@app.route("/")
def Index():
return render_template('index.html')
@app.route("/success", methods =['POST'])
def success():
if request.method=='POST':
email = request.form["email_name"]
height = request.form["height_name"]
print(email, height)
data = Data(email,height)
db.session.add(data)
db.session.commit()
return render_template('success.html')
if __name__ == '__main__':
app.debug = True
app.run()
当我执行代码时,这就是我得到的:
(virtual) C:\Users\lenovo\Desktop\My_Python\Py_html> py -3 App10.py
Traceback (most recent call last):
File "App10.py", line 1, in <module>
from flask import Flask, render_template, request
ModuleNotFoundError: No module named 'flask'
即使我确实重新安装了软件包,但我无法解决问题
解决方案
在控制台中,当您键入时 py -3 App10.py
,您可能没有使用虚拟环境的 python(您安装 Flask 的位置),而是使用默认的(您的 PATH 的)。
如果您在目录中使用 virtualenv 创建了一个虚拟环境,C:\Users\lenovo\Desktop\My_Python\venv
您可能想尝试以下操作:
C:\Users\lenovo\Desktop\My_Python\venv\Scripts\python.exe App10.py
推荐阅读
- android - CollapsingToolbarLayout 包含 ViewPager 和一个搜索框。如何防止搜索框仅折叠,而 ViewPager 折叠
- scala - scala 和 dotty 的下限和上限类型
- javascript - JavaScript:打印动态值/数据
- google-cloud-platform - GCP:创建包括运行时进程的 VM 快照
- java - 在用户的 gmail 中更新时,无法更新 firebase 数据库中的数据
- python-3.x - psycopg2 不会将数据保存到 postgres 数据库中
- javascript - 无法使用 JQuery 获取输入字段的值
- amazon-web-services - AWS 为 S3 文件夹级别访问生成动态凭证?
- javascript - d3js连续节点颜色网络 - 无法找出问题
- java - 如何仅使用循环(无数组)找到第二高分