Vic*_*Kay 41 python sqlalchemy pylint flask python-3.x
我目前正在尝试实现 Steam 登录网站。但是我无法在代码中传递这个错误。我已经创建了数据库对象,但它一直显示我之前提到的错误。我不确定 SQLAlchemy 是否发生了变化,或者自从我使用它以来发生了什么变化。
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
Run Code Online (Sandbox Code Playgroud)
发出的消息pylint
是
E1101: Instance of 'SQLAlchemy' has no 'Column' member (no-member)
Run Code Online (Sandbox Code Playgroud)
Adi*_*tya 65
编辑:阅读并尝试np8 的答案后,我之前的答案是错误的,您必须安装一个软件包,即pylint_flask_sqlalchemy
所以答案是
在您的项目目录中找到文件夹.vscode
(如果您没有,只需创建它)然后创建文件settings.json
并添加这一行
{
# You have to put it in this order to make it works
"python.linting.pylintArgs": [
"--load-plugins",
"pylint_flask_sqlalchemy",
"pylint_flask", # This package is optional
]
}
Run Code Online (Sandbox Code Playgroud)
您还需要有pylint-flask-sqlalchemy并且如果您想在当前的 python 环境中使用pylint-flask install:
pip install pylint-flask-sqlalchemy
pip install pylint-flask
Run Code Online (Sandbox Code Playgroud)
小智 21
pip install pylint-flask
Run Code Online (Sandbox Code Playgroud)
对于Visual Studio Code:在settings.json 中打开文件 > 首选项 > 设置 > 编辑,如下所示:
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
Run Code Online (Sandbox Code Playgroud)
fil*_*l_J 18
打开命令面板(macOS 上为 Command+Shift+P,Windows/Linux 上为 Ctrl+Shift+P)并输入以下命令之一:
Python: Select Linter
Run Code Online (Sandbox Code Playgroud)
从 PyLint 切换到 flake8 或其他支持的 linter。
np8*_*np8 18
似乎可以通过多种方式错误地配置它,因此我决定将不同的选项写下来。我假设使用 VS Code,但对于命令行或其他编辑器,参数及其顺序是相同的。这些都使用所有软件包的最新版本进行了测试(在本文底部列出)
# What you'll need is pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
# You can add pylint_flask but only if it is *AFTER* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
Run Code Online (Sandbox Code Playgroud)
# pylint_flask does not help, but can break it (see below)
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
# You can NOT add pylint_flask *BEFORE* pylint_flask_sqlalchemy
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
# CAUTION: These will disable pylint silently altogether!
# Do not use dash (-) but underscore (_)!
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask"]
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask-sqlalchemy"]
Run Code Online (Sandbox Code Playgroud)
的pylint的烧瓶-SQLAlchemy的1是专为解决这个问题2。您可以通过将其添加到--load-plugins
pylint来启用它。在命令行中,这将是
python -m pylint --load-plugins pylint_flash_sqlalchemy <mymodule.py>
Run Code Online (Sandbox Code Playgroud)
并在VS Code(设置(JSON))中:
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
Run Code Online (Sandbox Code Playgroud)
1也镜像到 GitHub:https : //github.com/anybox/pylint_flask_sqlalchemy
2请参阅pylint 问题跟踪器上的此评论。
pylint-flask是Flask 的pylint 插件。它与 Flask-SQLAlchemy 无关,它甚至没有尝试解决pylint 与 Flask-SQLAlchemy 3的误报问题。使用 pylint-flask 来“使错误消失”的唯一可能性是错误地用破折号加载它,这会使整个 pylint 被禁用。
看来pylint-flask必须在pylint-flas-sqlalchemy之后加载;我用我的设置进行了测试,出于某种原因
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
Run Code Online (Sandbox Code Playgroud)
将无法正常工作,但
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
Run Code Online (Sandbox Code Playgroud)
将要。所以加载插件的顺序很重要。
3自己看代码:pylint-flask source & pylint-flask-sqlaclhemy source
正如pylint-flask和pylint-flask- sqlalchemy的文档所说,参数中的名称--load-plugins
应该用下划线书写;如果你使用
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
Run Code Online (Sandbox Code Playgroud)
在 VS Code 中,错误会消失,但是当 pylint 在后台静默崩溃时,所有的 linting 也会消失。
pip install pylint-flask-sqlalchemy
Run Code Online (Sandbox Code Playgroud)
Flask 1.1.2
Flask-SQLAlchemy 2.4.4
pylint 2.5.3
pylint-flask 0.6
pylint-flask-sqlalchemy 0.2.0
Run Code Online (Sandbox Code Playgroud)
Ven*_*emo 13
我刚刚遇到这个问题。建议的解决方案都不适用于我,但以下方法适用。
首先,安装这些模块:
pip install pylint-flask
pip install pylint-flask-sqlalchemy
Run Code Online (Sandbox Code Playgroud)
然后,在Visual Studio Code 中,您需要将以下内容添加到您的settings.json
文件中:
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
Run Code Online (Sandbox Code Playgroud)
小智 6
对于 Windows,这是有效的:对于 Visual Studio Code:打开文件 > 首选项 > 设置 > 在 settings.json 中编辑 -> 并在现有设置下方的逗号后添加此代码:
"python.linting.pylintArgs": [
"--load-plugins",
"pylint-flask"
]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
37185 次 |
最近记录: |