VSCode pylint not displaying relative import failures - python

I am running a Django application in VSCode, using pylint, and the relative imports errors are not displaying. They were before I installed a newer version of VSCode.
I have tried changing user settings and also workspace settings, but still can't get the errors to show.
User Settings
{
"window.zoomLevel": 1,
"explorer.confirmDelete": false,
"workbench.startupEditor": "newUntitledFile",
"window.menuBarVisibility": "default",
"explorer.confirmDragAndDrop": false,
"workbench.colorTheme": "Visual Studio Dark",
"update.enableWindowsBackgroundUpdates": false,
"update.channel": "none",
"php.validate.run": "onSave",
}
Workspace settings
{
"python.linting.enabled": true,
"python.linting.pep8Enabled": false,
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
"python.linting.pylintEnabled": true,
"python.pythonPath": "/home/justin/anaconda3/bin/python",
"python.linting.pylintPath": "/home/justin/anaconda3/bin/pylint"
}
At the top of one of my functions, a couple of different relative imports. Which one is right or wrong, VSCode should show me. Both imports are in the same project directory in Django, therefore import should be a single '.' I believe.
from .performance import get_perf_dates, get_perf_data
from ..models import DistributionList, Legend

Related

VSCode isn't running PyLint (pylint runs in terminal fine)

My Pylint isn't picking up errors in VSCode.
if I run pylint file.py in the terminal I get the following ouptut:
************* Module file
file.py:38:27: E0001: invalid syntax (<unknown>, line 38) (syntax-error)
so I feel like I can be pretty sure Pylint has installed okay
However, in the Problems tab on VS Code, all I can see is "No problems have been found in the workspace so far". I've intentionally made a number of different errors to test it and none of them are being found by Pylint.
In settings, linting is definitely enabled and set to run on save. If I run CTRL + shift + P and then choose "Run Linting" I still don't get any problems found.
My settings.json are:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
"git.confirmSync": false,
"python.linting.enabled": true,
"window.zoomLevel": 0,
"python.pythonPath": "C:\\Users\\becky\\anaconda3\\python.exe",
"files.autoSave": "off",
"terminal.integrated.automationShell.linux": "",
"python.linting.pylintEnabled": true,
"python.linting.pylintUseMinimalCheckers": false,
"python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
"terminal.integrated.env.linux": {
},
"python.linting.pylintCategorySeverity.convention": "Hint",
"terminal.integrated.automationShell.windows": ""
}
I'm really lost here, I'd really appreciate any help with this because I'm not too sure where else to look!
Thanks!

Visual Studio Code won't open .py, .ipynb files

I have Visual Studio Code installed with the Python extension. When I try to open a .py or .ipynb file from the Windows File Explorer with VSCode, nothing opens and I get the windows "ding" sound instead (the same sound you get when a popup prevents you from interacting with other apps until you dismiss the popup). I tried user settings with and without file.associations, but either case did not work. Everything seems to work fine when from VSCode I choose File>>Open Folder and then browse to the .py or .ipynb file. Any idea why this is happening?
{
"python.dataScience.sendSelectionToInteractiveWindow": true,
"python.testing.unittestEnabled": true,
"editor.renderWhitespace": "selection",
"editor.renderControlCharacters": false,
"window.zoomLevel": -1,
"workbench.colorTheme": "Visual Studio Dark",
"python.linting.pycodestyleCategorySeverity.E": "Information",
"python.linting.pycodestyleCategorySeverity.W": "Information",
"editor.minimap.showSlider": "always",
"editor.minimap.maxColumn": 100,
"python.linting.pycodestyleEnabled": true,
"editor.accessibilitySupport": "off",
"[xml]": {},
"python.dataScience.askForKernelRestart": false,
"git.enableSmartCommit": true,
"[jsonc]": {},
"editor.minimap.size": "fill",
"editor.tabSize": 2,
"python.dataScience.textOutputLimit": 0,
"files.associations": {
"*.py": "python",
"*.ipynb": "python",
"*.pyt": "python"
},
"python.pythonPath": "c:\\my\\env\\Python.exe",
"python.linting.pylintEnabled": false,
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
}
I don't believe that shell file associations are set up with VS Code by default. files.associations setting is just to tie file extensions to the type of code inside visual studio code itself. If you right-click on a .py file do you see an option Open With=>Visual Studio Code? That option should be available to open it in VS Code.
If you want that to be default you can right click it in the shell and pick Open With=>Choose another app to select VSCode as the default app to open that item with.

Visual Studio Code ignores settings.json field: python.pythonPath

I can't seem to get my settings.json file to influence how python is invoked in VSCode when selecting "Run Code" (default hot key Ctrl + Alt + N), my user settings.json is as follows:
{
"python.pythonPath": "/usr/bin/python3",
"editor.suggestSelection": "first",
"vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
"python.jediEnabled": true,
"editor.minimap.enabled": true,
"editor.multiCursorModifier": "ctrlCmd",
"workbench.tree.indent": 24,
"workbench.startupEditor": "untitled",
"workbench.settings.editor": "json",
"workbench.settings.openDefaultKeybindings": false,
"workbench.settings.openDefaultSettings": true,
"workbench.settings.useSplitJSON": false,
"explorer.confirmDragAndDrop": false,
"python.linting.enabled": true,
"python.languageServer": "Jedi",
}
yet when I run my python file, not debug it, it is showing:
[Running] python -u "path/to/file.py"
when I am expecting (as I set python.pythonPath in settings.json):
[Running] /usr/bin/python3 -u "path/to/file.py"
Why is my settings.json file key python.pythonPath having no effect on how my code is invoked?
Among other important reasons, my python code doesn't even run as python invokes python 2 on my machine when my code is written in python 3.
VSCode version:
Version: 1.47.3
Commit: 91899dcef7b8110878ea59626991a18c8a6a1b3e
Date: 2020-07-23T15:51:39.791Z (1 mo ago)
Electron: 7.3.2
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0
OS: Linux x64 4.15.0-112-generic
From vscode-python-DeprecatePythonPath, python.pythonPath setting is being removed from all 3 scopes - User, workspace, workspace folder. The path to the workspace interpreter will now be stored in VS Code’s persistent storage instead of the settings.json file. That's why your setting has no effect on code execution path. You can change the value stored in workspace settings using Python: Select Interpreter command, or add the setting in User settings.json:
"python.defaultInterpreterPath":

PyLint shows "Unable to import" error with app's module file in Django project

I have an app named "diary" in my Django project:
school_diary/
diary/
<standart files inside app>
views.py
forms.py
Inside my views.py I make this import:
from . import forms
PyLint marks it as error. Here's what I have inside my settings.json:
{
...,
"python.linting.enabled": true,
"on.linting.pylintEnabled": true,
"python.linting.lintOnSave": true,
"python.linting.maxNumberOfProblems": 200,
"python.linting.pylintPath": "/home/alantheknight/Python/Environments/secenv/bin/pylint",
"python.pythonPath": "/home/alantheknight/Python/Environments/secenv/bin/python3.7",
...
Also, I read about generating .pylintrc, so I ran this command:
$ pylint --generate-rcfile > ~/.pylintrc
Where have I made a mistake?
This is a common error that most people come across.
You have not installed pylint in the same environment that contains your python packages.
The environment selected in VS Code is displayed at the bottom left on the status bar of VS Code.
Take a look at stackoverflow/pylint-unable-to-import-error-how-to-set-pythonpath.
and also pythonVSCodeDocs/docs/troubleshooting_linting

Visual Code pylint: unable to import webapp2 and google.appengine.api

I am new to using Visual Code on Ubtuntu... But I followed all necessary instructions to install google app engine for python.
Then on writing my python code on the Visual Code, which I already modified my USER SETTINGS :
{
"python.autoComplete.extraPaths": [
"/usr/local/google_appengine",
"/usr/local/google_appengine/lib"],
"python.autoComplete.addBrackets": true,
"workbench.welcome.enabled": false,
"workbench.iconTheme": "vscode-icons",
"python.pythonPath": "/usr/bin/python",
}
Please how I can resolve this?
Add the following library paths to your "python.autoComplete.extraPaths" list:
"/usr/local/google_appengine/api",
"/usr/local/google_appengine/lib/webapp2-2.5.2"

Categories