I am trying to set up Python Anaconda for Visual Studio Code, I can set the interpreter to run as python however when I run it I get an error message saying: "The Python path in your debug configuration is invalid.", when I open the launch.json I get the following output:
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config.python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
I am not entirely sure what I should change here to make it work?
Any ideas are very welcome as I am not able to find anything on this on google
Edit: This is how my editor looks: https://imgur.com/a/xoFmxc6
Related
I have been using Visual Studio Code for a few years and I find it a really good IDE. I program in Python more than any other language.
It really bothers me that I did not get around to using the IDE's debugger (even though it's a feature).
Error when pressing the debug play button:
Failed to launch the Python Process, please validate the path 'export PATH=$PATH:/Library/Frameworks/Python.framework/Versions/2.7/bin/python'
Checking my PYTHONPATH:
My launch.json file:
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "/workspace/h5-automation/",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
Any ideas / suggestions?
If you are on a *nix system, launch the terminal and type which python to get the Python path, copy it and paste it as the value of pythonPath in the launch.json file.
I've just started using VS Code with the Python plugin. I've set up a venv, launched code within that venv, installed all my necessary modules and updated my launch.json to launch flask apps as follows:
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceFolder}/env/Scripts/flask.exe",
"cwd": "${workspaceFolder}",
"env": {
"FLASK_APP": "${workspaceFolder}/main.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
},
However when I launch the debugger for Flask in VS Code the following appears in my debug console:
ValueError: source code string cannot contain null bytes
However, if I just launch the app from the commandline doing:
set FLASK_APP=main.py
python -m flask
it works just fine. I'm sure it's something stupid I've done but I can't figure out what that is.
Note also that pythonPath points to my venv python installation.
I am seeing the ValueError as well, and haven't found a proper solution for this, but have a workaround, using the "module": "flask":
{
"name": "Python: Flask (0.11.x or later)",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
//"program": "${workspaceFolder}/env/Scripts/flask.exe",
"module": "flask",
"cwd": "${workspaceFolder}",
"env": {
"FLASK_APP": "${workspaceFolder}/main.py"
},
"args": [
"run",
"--no-debugger",
"--no-reload"
],
"envFile": "${workspaceFolder}/.env",
"debugOptions": [
"RedirectOutput"
]
}
It does, however, take some time to start the Flask app each time I start debugging, not sure if this is due to Flask being started via Python. Invoking flask.exe and python.exe -m flask from the command line seems to be evenly fast - notably faster than starting debugging in VS Code.
I set up a python project in visual studio code and this is the debugging option I'm using in my launch.json:
{
"name": "External Terminal/Console",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "",
"console": "externalTerminal",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit"
]
}
I installed pylint and created a settings.json file which looks exactly like this:
{
"python.linting.pep8Enabled": true,
"python.linting.pep8Path": "/usr/bin/pep8",
"python.linting.pylintPath": "/usr/bin/pylint"
}
The pylint linter errors are being displayed but there is no lightbubble showing up which helps fixing linter errors automatically.
What is causing this and how can I enable the lightbubble which helps me to fix the linter errors e.g. Fix all autofixable errors.?
Yes, there is no lightbubble from Pylint.
If you need a linter with lightbubble, try SonarLint.
I'm new to python (and in coding in general). I'd like to ask some help to set up python on VS Code. I've tried to follow several guides but none of them were really helpful.
The following have been downloaded:
Python 3.6
VS Code
Python extensions
1) Install VS Code
2) Go to View > Command Palette
3) Type ext install and click on Install Extensions
4) Search for Python and install it
5) Reload VS
6) Start coding
This worked for me:
.vscode/settings.json:
{
"python.linting.pylintEnabled": false,
"python.pythonPath": "python.exe"
}
.vscode/tasks.json:
{
"version": "2.0.0"
}
.vscode/launch.json:
{
"version": "2.0.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": false,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"console": "internalConsole",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
}
]
}
You can replace "program": "${file}", with "program": "${workspaceRoot}/main.py", to run your main file no matter which file you've selected but I found that that makes errors like syntax errors sometimes not display correctly if at all.
Breaking on exceptions
Press CTRL + SHIFT + D
In the BREAKPOINTS panel, click on Uncaught Exceptions
enter image description here
I would like to have possibility to do a debugging of Django application in Visual Studio Code. I have a virtualenv, made a change in launch.json file that look like this:
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${workspaceRoot}/.venv/bin/python2.7",
"program": "${workspaceRoot}/mysite/manage.py",
"args": [
"runserver"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"DjangoDebugging",
"RedirectOutput"
]
},
put several break points in the code and run it. Unfortunately, the execution is not stopped on the line with break points. I tried the same without virtualenv and everything worked perfectly.
Please, point out what I am doing wrong here.
For me, the following 2 changes worked
Add an absolute path for pythonPath
Use the "--noreload" option while starting the project
Here's the relevant part of my config
{
"name": "Django",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "/Users/xyz/Documents/dev/my_project/my_project_env/bin/python",
"program": "${workspaceRoot}/manage.py",
"args": [
"runserver",
"0.0.0.0:8080",
"--noreload"
],
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput",
"DjangoDebugging"
]
},
1) Press CTRL + ,
2) Select Workspace Settings
3) Add the following line in the settings file opened.
"python.pythonPath": "path_to_your_env"
You're done!
This official tutorial worked in my case.
Just needed to open the "command palette" of VS Code and select my Python Interpreter to the virtual environment:
Full reference: https://code.visualstudio.com/docs/python/tutorial-django#_create-a-project-environment-for-the-django-tutorial