即使安装了flask-sqlachemy后我也无法导入flask_sqlalchemy
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
# ^this line shows error ImportError: "flask_sqlalchemy" could not be resolved
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
Run Code Online (Sandbox Code Playgroud)
我没有使用任何虚拟环境,flask-sqlalchemy 显示已安装
(base) sachin@sachin:~/Coding/flask/blog$ pip install Flask-SQLAlchemy
Requirement already satisfied: Flask-SQLAlchemy in /home/sachin/anaconda3/lib/python3.8/site-packages (2.4.4)
Requirement already satisfied: SQLAlchemy>=0.8.0 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Flask-SQLAlchemy) (1.3.20)
Requirement already satisfied: Flask>=0.10 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Flask-SQLAlchemy) (1.1.2)
Requirement already satisfied: Jinja2>=2.10.1 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.11.2)
Requirement already satisfied: itsdangerous>=0.24 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (1.1.0)
Requirement already satisfied: click>=5.1 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (7.1.2)
Requirement already satisfied: Werkzeug>=0.15 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Flask>=0.10->Flask-SQLAlchemy) (1.0.1)
Requirement already satisfied: MarkupSafe>=0.23 in /home/sachin/anaconda3/lib/python3.8/site-packages (from Jinja2>=2.10.1->Flask>=0.10->Flask-SQLAlchemy) (1.1.1)
Run Code Online (Sandbox Code Playgroud)
pip freeze 显示它已经安装 -
Flask==1.1.2
Flask-SQLAlchemy==2.4.4
Run Code Online (Sandbox Code Playgroud)
小智 11
我有同样的错误。通过在 VS Code 中执行以下操作更改了我的系统 python:在视图菜单下选择“显示命令托盘”。然后,您可以从命令选项板中选择的命令之一是“Python:选择解释器”。选择此选项将允许您选择要使用的 python 版本。
这篇文章已经很老了,但我找到了一个不同的解决方案,可能会帮助其他人。对我来说,问题是我的 IDE/Python (venv)。我正在使用 Visual Studio 版本。截至目前,Windows 10 上的版本为 1.57.1。
project_folder/venv/Scripts.python.exe或pythonw.exe在您的project_folder/venv/Scripts文件夹内。就这样。
Flask-SQLAlchemy 安装在我的虚拟环境 (venv) 中。但我的 VSCode 使用系统/PC Python 解释器来查找包而不是 venv。
希望这可以帮助其他人。
| 归档时间: |
|
| 查看次数: |
19833 次 |
| 最近记录: |