def index(request):
latest_question_list = Question.objects.all().order_by('-pub_date')[:5]
template = loader.get_template('polls/index.html')
context = {'latest_question_list':latest_question_list}
return HttpResponse(template.render(context, request))
The first line of that function gets an error on Question.objects.all():
E1101: Class 'Question' has no 'objects' member
I'm following the Django documentation tutorial and they have the same code up and running.
I have tried calling an instance.
Question = new Question()
and using MyModel.objects.all()
Also my models.py code for that class is this...
class Question(models.Model):
question_text = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
def __str__(self):
return self.question_text
To no avail I still have this error.
I have read about pylint and ran this...
pylint --load-plugins pylint_django
Which didn't help, even tho the github readme file says...
Prevents warnings about Django-generated attributes such as
Model.objects or Views.request.
I ran the command within my virtualenv, and yet nothing.
So any help would be great.
Install pylint-django using pip as follows
pip install pylint-django
Then in Visual Studio Code goto: User Settings (Ctrl + , or File > Preferences > Settings if available ) Put in the following (please note the curly braces which are required for custom user settings in VSC):
{"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],}
#tieuminh2510's answer is perfect. But in newer versions of VSC you will not find the option to edit or paste that command in User Settings.
For newer versions, add the code in the following steps:
Press ctrl shift p to open the the Command Palette.
Now in Command Palette type Preferences: Configure Language Specific Settings.
Select Python.
Add these lines inside the first curly braces:
"python.linting.pylintArgs": [
"--load-plugins=pylint_django",
]
Make sure that pylint-django is also installed.
Install Django pylint:
pip install pylint-django
ctrl+shift+p > Preferences: Configure Language Specific Settings > Python
The settings.json available for python language should look like the below:
{
"python.linting.pylintArgs": [
"--load-plugins=pylint_django"
],
"[python]": {
}
}
I've tried all possible solutions offered but unluckly my vscode settings won't changed its linter path. So, I tride to explore vscode settings in settings > User Settings > python. Find Linting: Pylint Path and change it to "pylint_django". Don't forget to change the linter to "pylint_django" at settings > User Settings > python configuration from "pyLint" to "pylint_django".
Heres the answer.
Gotten from my reddit post...
https://www.reddit.com/r/django/comments/6nq0bq/class_question_has_no_objects_member/
That's not an error, it's just a warning from VSC. Django adds that
property dynamically to all model classes (it uses a lot of magic
under the hood), so the IDE doesn't know about it by looking at the
class declaration, so it warns you about a possible error (it's not).
objects is in fact a Manager instance that helps with querying the DB.
If you really want to get rid of that warning you could go to all your
models and add objects = models.Manager() Now, VSC will see the
objects declared and will not complain about it again.
UPDATE FOR VS CODE 1.40.0
After doing:
$ pip install pylint-django
Follow this link: https://code.visualstudio.com/docs/python/linting#_default-pylint-rules
Notice that the way to make pylint have into account pylint-django is by specifying:
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
in the settings.json of VS Code.
But after that, you will notice a lot of new linting errors. Then, read what it said here:
These arguments are passed whenever the python.linting.pylintUseMinimalCheckers is set to true (the default). If you specify a value in pylintArgs or use a Pylint configuration file (see the next section), then pylintUseMinimalCheckers is implicitly set to false.
What I have done is creating a .pylintrc file as described in the link, and then, configured the following parameters inside the file (leaving the rest of the file untouched):
load-plugins=pylint_django
disable=all
enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode
Now pylint works as expected.
You can change the linter for Python extension for Visual Studio Code.
In VS open the Command Palette Ctrl+Shift+P and type in one of the following commands:
Python: Select Linter
when you select a linter it will be installed. I tried flake8 and it seems issue resolved for me.
Just adding on to what #Mallory-Erik said:
You can place objects = models.Manager() it in the modals:
class Question(models.Model):
# ...
def was_published_recently(self):
return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
# ...
def __str__(self):
return self.question_text
question_text = models.CharField(max_length = 200)
pub_date = models.DateTimeField('date published')
objects = models.Manager()
Change your linter to - flake8 and problem will go away.
I was able to update the user settings.json
On my mac it was stored in:
~/Library/Application Support/Code/User/settings.json
Within it, I set the following:
{
"python.linting.pycodestyleEnabled": true,
"python.linting.pylintEnabled": true,
"python.linting.pylintPath": "pylint",
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"]
}
That solved the issue for me.
First install pylint-django using following command
$ pip install pylint-django
Then run the second command as follows:
$ pylint test_file.py --load-plugins pylint_django
--load-plugins pylint_django is necessary for correctly review a code of django
If you use python 3
python3 -m pip install pylint-django
If python < 3
python -m pip install pylint-django==0.11.1
NOTE: Version 2.0, requires pylint >= 2.0 which doesn’t support Python 2 anymore! (https://pypi.org/project/pylint-django/)
First, Install pylint-django using pip as follows:
pip install pylint-django
Goto settings.json find and make sure python linting enabled is true
like this:
At the bottom write "python.linting.pylintPath": "pylint_django"like this:
OR,
Go to Settings and search for python linting
make sure Python > Linting: Pylint Enabled is checked
Under that Python > Linting: Pylint Path write pylint_django
How about suppressing errors on each line specific to each error?
Something like this: https://pylint.readthedocs.io/en/latest/user_guide/message-control.html
Error: [pylint] Class 'class_name' has no 'member_name' member
It can be suppressed on that line by:
# pylint: disable=no-member
I installed PyLint but I was having the error Missing module docstringpylint(missing-module-docstring). So I found this answer with this config for pylint :
"python.linting.pylintEnabled": true,
"python.linting.pylintArgs": [
"--disable=C0111", // missing docstring
"--load-plugins=pylint_django,pylint_celery",
],
And now it works
By doing Question = new Question() (I assume the new is a typo) you are overwriting the Question model with an intance of Question. Like Sayse said in the comments: don't use the same name for your variable as the name of the model. So change it to something like my_question = Question().
This issue happend when I use pylint_runner
So what I do is open .pylintrc file and add this
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=objects
Just add objects = None in your Questions table. That solved the error for me.
Related
This happens to me almost every day:
pip isntall matplotlib --upgrade
ERROR: unknown command "isntall" - maybe you meant "install"
There is one obvious solution; learn how to type install correctly. So far, that hasn't gone well
I've been wondering, is there a way to instead have pip run the install command when I type isntall? It already recommends the solution, so why not just run it instead of making me type it again.
I'm aware of how silly of a question this is, but I honestly can't seem to type install correctly (I've had to correct it twice already in this question)
You can use thufuck, when you make a typo like this, just write fuck, you can also customize this later, and it will show the probably correct way to do it.
https://github.com/nvbn/thefuck
You can create a function to solve this (stick it in your .bashrc or what-have-you).
pip() {
if [[ $1 == "isntall" ]]; then
command pip install ${#: 2}
else;
command pip $#
fi
}
If I wrote that correctly it will catch your mispeling and run the command properly.
Disclaimer
This is not a solution to be taken seriously, rather of the "you can do this a well" kind. The code uses knowledge of internal pip implementation and may break on new release of pip.
You can patch the related pip logic in a custom sitecustomize module. Create a file sitecustomize.py with the following contents:
import re
import pip._internal.cli.main_parser as pip_cli_parser
from pip._internal.exceptions import CommandError
error_pattern = re.compile(
r'unknown command "(?P<cmd>.*?)"(?: - maybe you meant "(?P<guess>.*?)")?'
)
parse_command_orig = pip_cli_parser.parse_command
def parse_command(args):
try:
return parse_command_orig(args)
except CommandError as err:
msg = str(err)
cmd_name, guess = error_pattern.search(msg).groups()
if guess is not None:
cmd_args = args[:]
cmd_args.remove(cmd_name)
return guess, cmd_args
else:
raise err
pip_cli_parser.parse_command = parse_command
Place the file in the site-packages directory where pip is installed to. You can find it e.g. by running pip -V:
$ pip -V
pip 21.2.3 from /tmp/tst/lib64/python3.10/site-packages/pip (python 3.10)
The target directory in this example is thus /tmp/tst/lib64/python3.10/site-packages.
Now pip's command parser will be patched each time a Python process starts:
$ pip lit # instead of 'list'
Package Version
---------- -------
pip 22.0.4
setuptools 57.4.0
I ended up editing the a file in the pip folder to add an sintall command. In [path_to_python]\Lib\site-packages\pip_internal\commands_init_.py, there is a dictionary that looks like this...
commands_dict: Dict[str, CommandInfo] = {
"install": CommandInfo(
"pip._internal.commands.install",
"InstallCommand",
"Install packages.",...
And I just added a dictionary entry for 'isntall'
"isntall": CommandInfo(
"pip._internal.commands.install",
"InstallCommand",
"Install packages.",
)
Definitely not an ideal solution because any new env of update would require the same edit, but for now it's working well and doesn't require any new typing after the typo. DEfinitely still happy to hear a better answer
I am the author of django-persistent-settings. I have realized something odd.
The app has various management commands. When I do python setup.py --help in django-persistent-settings project, the management commands do show up:
[persistent_settings]
delvar
getvar
setvar
These commands are also tested in the library. However, these commands do not show up when I install it to a project. I wonder why that is.
I have read the related section of the docs but could not have found a warning, subsection or something alike regarding my problem. I have also checked the source code of some other projects having custom management commands such as django-simple-history or django-rest-framework. They do more or less the same thing.
Is there maybe something I don't know? An issue I haven't seen but encountered somehow?
Reanimating the Unexpected Behavior
Make sure Django 2 is installed and create a dummy project.
django-admin --version
# django 2.2.12 or something similar
django-admin createproject foo
cd foo
virtualenv .venv
source .venv/bin/activate
pip install "django<3" django-persistent-settings
Open up foo/settings.py and add it INSTALLED_APPS:
INSTALLED_APPS = [
# ...
"persistent_settings"
]
List commands:
python setup.py --help
And the commands do not show up.
Environment
Python 3.8
Django 2.2.12
I forgot to add management package to setup.py. A dumb mistake.
Remember to add your management command subpackages to packages kwarg in setup.py.
setup(
# ...
packages=(
"persistent_settings",
"persistent_settings.migrations",
"persistent_settings.templatetags",
"persistent_settings.management", # add this line
"persistent_settings.management.commands", # and this line
)
# ...
)
i'm using vscode for python3 in Ubuntu. Error-squiggle-lines have stopped working for Python(it works for other languages). And I am using Microsoft's Python extension.
vscode v1.41.1
Ubuntu v18.04
this is what i have tried:
I thought maybe it's because i installed anaconda so uninstalled it but didn't fix it.
then I re-installed vs code after deleting its config from .config/code but that didn't work either.
also set python linting to true from command palette
it's not showing error squiggle lines:
here is the Microsoft's python extension's contributions regarding linting(sorry for poor readability):
Whether to lint Python files. true python.linting.flake8Args Arguments passed in. Each argument is a separate item in the array. python.linting.flake8CategorySeverity.E Severity of Flake8 message type 'E'. Error python.linting.flake8CategorySeverity.F Severity of Flake8 message type 'F'. Error python.linting.flake8CategorySeverity.W Severity of Flake8 message type 'W'. Warning python.linting.flake8Enabled Whether to lint Python files using flake8 false python.linting.flake8Path Path to flake8, you can use a custom version of flake8 by modifying this setting to include the full path. flake8 python.linting.ignorePatterns Patterns used to exclude files or folders from being linted. .vscode/*.py,**/site-packages/**/*.py python.linting.lintOnSave Whether to lint Python files when saved. true python.linting.maxNumberOfProblems Controls the maximum number of problems produced by the server. 100 python.linting.banditArgs Arguments passed in. Each argument is a separate item in the array. python.linting.banditEnabled Whether to lint Python files using bandit. false python.linting.banditPath Path to bandit, you can use a custom version of bandit by modifying this setting to include the full path. bandit python.linting.mypyArgs Arguments passed in. Each argument is a separate item in the array. --ignore-missing-imports,--follow-imports=silent,--show-column-numbers python.linting.mypyCategorySeverity.error Severity of Mypy message type 'Error'. Error python.linting.mypyCategorySeverity.note Severity of Mypy message type 'Note'. Information python.linting.mypyEnabled Whether to lint Python files using mypy. false python.linting.mypyPath Path to mypy, you can use a custom version of mypy by modifying this setting to include the full path. mypy python.linting.pycodestyleArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pycodestyleCategorySeverity.E Severity of pycodestyle message type 'E'. Error python.linting.pycodestyleCategorySeverity.W Severity of pycodestyle message type 'W'. Warning python.linting.pycodestyleEnabled Whether to lint Python files using pycodestyle false python.linting.pycodestylePath Path to pycodestyle, you can use a custom version of pycodestyle by modifying this setting to include the full path. pycodestyle python.linting.prospectorArgs Arguments passed in. Each argument is a separate item in the array. python.linting.prospectorEnabled Whether to lint Python files using prospector. false python.linting.prospectorPath Path to Prospector, you can use a custom version of prospector by modifying this setting to include the full path. prospector python.linting.pydocstyleArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pydocstyleEnabled Whether to lint Python files using pydocstyle false python.linting.pydocstylePath Path to pydocstyle, you can use a custom version of pydocstyle by modifying this setting to include the full path. pydocstyle python.linting.pylamaArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pylamaEnabled Whether to lint Python files using pylama. false python.linting.pylamaPath Path to pylama, you can use a custom version of pylama by modifying this setting to include the full path. pylama python.linting.pylintArgs Arguments passed in. Each argument is a separate item in the array. python.linting.pylintCategorySeverity.convention Severity of Pylint message type 'Convention/C'. Information python.linting.pylintCategorySeverity.error Severity of Pylint message type 'Error/E'. Error python.linting.pylintCategorySeverity.fatal Severity of Pylint message type 'Fatal/F'. Error python.linting.pylintCategorySeverity.refactor Severity of Pylint message type 'Refactor/R'. Hint python.linting.pylintCategorySeverity.warning Severity of Pylint message type 'Warning/W'. Warning python.linting.pylintEnabled Whether to lint Python files using pylint. true python.linting.pylintPath Path to Pylint, you can use a custom version of pylint by modifying this setting to include the full path. pylint python.linting.pylintUseMinimalCheckers Whether to run Pylint with minimal set of rules. true
python.linting.pylintEnabled is: true
python.linting.pylintPath is: pylint
all the errors in visual studio's console of developer tools:
console.ts:137 [Extension Host] Error Python Extension: 2020-01-18 18:35:53: Failed to serialize gatherRules for DATASCIENCE.SETTINGS [TypeError: Cannot convert object to primitive value at Array.join (<anonymous>) at Array.toString (<anonymous>) at /home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:12901 at Array.forEach (<anonymous>) at Object.l [as sendTelemetryEvent] (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:12818) at C.sendSettingsTelemetry (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:75:707093) at C.r.value (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:87512) at Timeout._onTimeout (/home/manik/.vscode/extensions/ms-python.python-2020.1.58038/out/client/extension.js:1:86031) at listOnTimeout (internal/timers.js:531:17) at processTimers (internal/timers.js:475:7)]
t.log # console.ts:137
2console.ts:137 [Extension Host] Notification handler 'textDocument/publishDiagnostics' failed with message: Cannot read property 'connected' of undefined
t.log # console.ts:137
2console.ts:137 [Extension Host] (node:21707) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
t.log # console.ts:137
$logExtensionHostMessage # mainThreadConsole.ts:39
_doInvokeHandler # rpcProtocol.ts:398
_invokeHandler # rpcProtocol.ts:383
_receiveRequest # rpcProtocol.ts:299
_receiveOneMessage # rpcProtocol.ts:226
(anonymous) # rpcProtocol.ts:101
fire # event.ts:581
fire # ipc.net.ts:453
_receiveMessage # ipc.net.ts:733
(anonymous) # ipc.net.ts:592
fire # event.ts:581
acceptChunk # ipc.net.ts:239
(anonymous) # ipc.net.ts:200
t # ipc.net.ts:28
emit # events.js:200
addChunk # _stream_readable.js:294
readableAddChunk # _stream_readable.js:275
Readable.push # _stream_readable.js:210
onStreamRead # internal/stream_base_commons.js:166
output for python in output panel:
User belongs to experiment group 'AlwaysDisplayTestExplorer - control'
User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'ShowExtensionSurveyPrompt - enabled'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'AA_testing - experiment'
> conda --version
> pyenv root
> python3.7 -c "import sys;print(sys.executable)"
> python3.6 -c "import sys;print(sys.executable)"
> python3 -c "import sys;print(sys.executable)"
> python2 -c "import sys;print(sys.executable)"
> python -c "import sys;print(sys.executable)"
> /usr/bin/python3.8 -c "import sys;print(sys.executable)"
> conda info --json
> conda env list
Starting Microsoft Python language server.
> conda --version
> /usr/bin/python3.8 ~/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
> /usr/bin/python3.8 ~/.vscode/extensions/ms-python.python-2020.1.58038/pythonFiles/interpreterInfo.py
how to get the squiggle lines to work again?
In your settings.json file(search for settings.json in the command palette), declare the following:
"python.linting.pylintEnabled": true, "python.jediEnabled": false
if you just want the changes in your workspace then change the settings.json file in .vscode folder
In latest version of visual studio code, workspace is not registering settings from checkboxes so you have to explicitly declare in settings.json what settings you want to enable for your workspace. Flake8 is not affected by this. Pylint and Microsoft Python Language Server seem to be not working due to this.
side note:got this solution from sys-temd's reply on github.com/microsoft/vscode-python/issues
What I tried but not working
pip install -U pylint
declare "python.linting.pylintEnabled": true, "python.jediEnabled": false
Then I try to recreate a brand-new settings.json, pylint turns out working.
Therefore, I trace which line affects pylint.
In my case, it's the line beginning from "python.linting.pylintArgs":
Solution
Removing the line beginning from "python.linting.pylintArgs": will solve the problem.
Make sure in your settings you didn't turn off linting (and specifically Pylint if that's what you want to use). Also make sure you have Pylint installed and the Python extension knows where it is (either by creating an environment and installing into there or installing it globally and setting "python.linting.pylintPath"). Otherwise check the output of the "Python" channel in the Output Panel to see how Pylint is being executed and make sure that works when you copy-and-paste it into a terminal as appropriate.
pip install -U pylint
Solved my issue
If the main problem is those squiggle lines or some minor errors in the workspace then you can download the 'pylance extension' and enable it in settings of 'python language server'. This language server is even better (i think) because it is lighter than 'jedi' language server and also tells about the unused modules and variables or even the undefined variables as those squiggle lines show.
I've some prob to setup my vscode project in python. I try to create a test to test my car module. But, I've always the error
no module found when I try to run ( test_whendrivecar.py)
test_whendrivecare inherited to context.context inherited to baseclasstest ( just some struct of GivenWhenThen test).
I tried to setup in sys.path(c:/users/me/drive) , but that doesn't work to run my test. I 've againt the error no module 'baseclasstest' found or no module 'car' found.
I 've same prob if I tried to create a module on same level that car directory.
here my project struc :
vscode 1.39.2
python 3.7.3
env: create by conda
test framework: unittest
what I tried:
put the path in settings.json "python.autoComplete.extraPaths" - > doesn't work
put the path in launch.json "env": "PYTHONPATH": -> doesn't work
can you help my ? I thought that is easy to use custom module/package in python.
Ohhh I know, python 3.3+ doesn't need init.py I just put that to be sure.
I looking on google, but I don't found anything to help me.
Try to add from drive.car.car import "your class" in your test
I'm currently trying to implement steam login into website. But I'm unable to get pass this error within the code. I've created the database object but it keeps showing the error I mentioned earlier. I'm not sure whether SQLAlchemy has changed or what since I used it.
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)
The message emitted by pylint is
E1101: Instance of 'SQLAlchemy' has no 'Column' member (no-member)
EDIT: After read and try np8's answer my previous answer is wrong there is a package you have to install, which is pylint_flask_sqlalchemy
so the answer will be
on your project directory find folder .vscode (if you dont have it, just create it) then create file settings.json and add this line
{
# 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
]
}
You also need to have pylint-flask-sqlalchemy and if you want to use pylint-flask install on your current python environment:
pip install pylint-flask-sqlalchemy
pip install pylint-flask
pip install pylint-flask
In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json as below:
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
Summary of working and non-working configurations
It seems that this can be configured so many ways incorrectly, that I decided to write the different options down. I am assuming VS Code, but for command line or other editor, arguments and their order is the same. These were tested using the latest versions of all the packages (list in the bottom of this post)
Working versions
# 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"]
Non-working versions
# 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"]
Details for those who are interested
pylint_flask_sqlalchemy
The pylint-flask-sqlalchemy1 was created specifically to fix this2. You can enable it by adding it to --load-plugins of pylint. In command line this would be
python -m pylint --load-plugins pylint_flash_sqlalchemy <mymodule.py>
and in VS Code (Settings (JSON)):
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy"]
1Also mirrored to GitHub: https://github.com/anybox/pylint_flask_sqlalchemy
2See this comment on pylint Issue tracker.
pylint_flask
pylint-flask is pylint plugin for Flask. It has nothing to do with Flask-SQLAlchemy and it does not even try to solve the false positive issues pylint has with Flask-SQLAlchemy3. The only possibility to use pylint-flask to "make the errors disappear" is to load it with erroneusly with dashes, which makes the whole pylint to be disabled.
It seems that pylint-flask must be loaded after pylint-flas-sqlalchemy; I tested with my setup, and for some reason
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask", "pylint_flask_sqlalchemy"]
will not work, but
"python.linting.pylintArgs": ["--load-plugins", "pylint_flask_sqlalchemy", "pylint_flask"]
will. So the order of loading plugins matters.
3 See the code for yourself: pylint-flask source & pylint-flask-sqlaclhemy source
Caution: Do not remove your linting accidentally
As the documentation of pylint-flask and pylint-flask-sqlalchemy says, the names in the argument --load-plugins should be written with underscores; If you use
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
in VS Code, the errors will be gone, but so will be all of your linting as the pylint crashes silently in the background.
Installing pylint-flask-sqlalchemy
pip install pylint-flask-sqlalchemy
Used versions
Flask 1.1.2
Flask-SQLAlchemy 2.4.4
pylint 2.5.3
pylint-flask 0.6
pylint-flask-sqlalchemy 0.2.0
See also
Discussion on pylint GitHub issue: "Problem with Flask-SQLAlchemy, cannot find valid and existing property in SQLAlchemy object."
Open the Command Palette (Command+Shift+P on macOS and Ctrl+Shift+P on Windows/Linux) and type in one of the following commands:
Python: Select Linter
Switch from PyLint to flake8 or other supported linters.
I've just encountered this issue. Neither of the suggested solutions worked for me, but the following does.
First, install these modules:
pip install pylint-flask
pip install pylint-flask-sqlalchemy
Then, in Visual Studio Code, you need to add the following to your settings.json file:
"python.linting.pylintArgs": ["--load-plugins", "pylint-flask", "pylint-flask-sqlalchemy"]
For Windows, this works: In case of Visual Studio Code: Open File > Preferences > Settings > Edit in settings.json ->
and add this code after comma below existing settings:
"python.linting.pylintArgs": [
"--load-plugins",
"pylint-flask"
]