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.
Related
I'm on a Jetson Nano Linux Ubuntu 18.4, remoting from a windows platform
using VS Code to develop python code.
I'm using Visual Studio Code's debugger and expecting the code to stop at several break points.
It doesn't. I'm thinking VSC can't find the .py file from the launch.json file? I don't know how to debug launch.json.
Any thoughts?
Python code:
#!/usr/bin/python3
import sys
import argparse
print(f'Length : {len(sys.argv)}')
if len(sys.argv) == 2:
print(f'Argv[1]: {sys.argv[1]}')
if len(sys.argv) == 2:
name = sys.argv[1]
else:
name = 'stranger'
print(f'Hi there, {name}')
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Hello World",
"type": "python",
"justMyCode": true,
"request": "launch",
"program": "${workspaceFolder}/build/bin/helloWorld.py",
"args": ["Steven"],
"console": "integratedTerminal",
"cwd": "${workspaceFolder}"
}
]
}
The runs without issue from the TERMINAL window:
steven#DEVELOPMENT-JETSON:~/Projects/test-python/helloWorld/build/bin$ ./helloWorld.py steven
Length : 2
Argv[1]: steven
Hi there, steven
Attempted 3 Different run attempts in Visual Studio Code:
A. right clicked on helloWorld.py from the Explorer window>> Clicked [Run Python File in Terminal]
Application runs in TERMINAL window and errors out as expected.
Application required an argument e.g $./helloWorld.py Steven. No where to
add a parm.
B. clicked Run >> clicked Run without debugging
Nothing happens except the debug window flashes on then off.
C. clicked Run >> clicked Start Debugging
Same result as B
Attached is a image of the Explorer window to show directory locations and break points:
There is no problem using debug for me.
You can try debugging like the picture.
After more research, I found that setting the Interpreter to Python 3.6.9-bit /usr/bin/python3 allowed VSC to enter debug mode. I was using the "Recommended" version. I don't know why VSC required the 3.6.9 version instead of the 3.7.9. I do have the 3.7.9 installed on the jetson.
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!
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":
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
Using Python3 with Visual Studio Code (Python extension installed) within Ubuntu 16.04.
I have some basic script written:
def mainMethod():
what()
#connectToDevice()
if __name__ == "__main__":
mainMethod()
When I debug this in Visual Studio Code by hitting F5 I can't see any output with the error in Debug Console:
Traceback (most recent call last):
File "main.py", line 9, in
mainMethod()
File "main.py", line 5, in mainMethod
what()
NameError: name 'what' is not defined
If I run python3 main.py in console the output appears.
How can I see those errors in VSCode and avoid switching back and forth between it and console?
I still can't see the output in Debug Console all the time but I can see it in the Integrated Terminal by setting this option in launch.json file of VSCode. The file looks like this:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python virtual env",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"console": "integratedTerminal",
"program": "${workspaceRoot}/main.py",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
],
"pythonPath": "${workspaceRoot}/env/bin/python3"
}
]
}
The core line is "console": "integratedTerminal". Also please note that this configuration is using the interpreter from the Virtual Environment folder and the file which starts is always main.py instead of the default option which runs the file from the active editor.
EDIT: it seems that later versions solved this problem so above workaround doesn't apply anymore
In the Feb 2018 update to VS Code this issue appears to be entirely resolved. So you don't need to make any changes to the default config, becuase the integrated debug terminal is finally printing errors when they occur.
A slightly better way, for me, is to just add "console": "externalTerminal" rather than internalTerminal. That opens a new terminal when debugging, but it's a clearer one and it closes almost automatically.
I have a similar problem in my case was the Python Linter didn't show the errors.
My mistake was, that I open the VS Code when a VirtualEnv was active. Whit the command
code .
To fixed I close VS Code, delete de .vs folder, deactivate de VirtualEnv, then open VS Code and then open VirtualEnv.
And done!, problem solve. Other solution in my case would be install the linter (if I remember right, pylint is the default linter for vscode).