I cannot figure out how to get VS Code for Mac to start debugging my Python script with the arguments I have defined in my launch.json file by using the debug button to the right I have circled here. The only way I can get my arguments to be recognized is if I go to the menu and select "Run|Start Debugging" or if press F5.
How do I tell VS Code to use my launch.json file when using that button???
If you look at the answer from Sourya Dey at the link below, this is what made me write this. There must be some simple setting or step missing to link that button to F5. It appears others are also confused about this.
Visual Studio Code: How debug Python script with arguments
For clarity, here is my launch.json file which works as expected with F5. It does not work with the button I have circled in red above
Update May 2022 from Microsoft tech support on github issues for vscode-python
You need to add this section to your launch.json file:
"purpose": ["debug-in-terminal"]
I just tested it on VS Code 1.67.1 and it works. The documentation appears to state that if you add this "flag" then F5 or Run > Debug won't use the launch.json settings but they do. I have asked them to update their docs to make this clearer as it is confusing.
============
I filed a bug with the Microsoft VS Code team regarding this issue and they sent me over to the Microsoft Python extension group. I then filed a bug there referencing the VC Code ticket and it was immediately assigned for "area-debugging triage". I presume this will be fixed in a later version (I am on 1.63.2)
First, it is not obvious where this button comes from. I have noted this issue as well with Microsoft so they can improve their documentation. When you install VS Code with no extensions, this button is not present. But as soon as you load your first Python file, Microsoft urges you to install the official "Microsoft Python Extension" and then the button shows up. In my mind, I assumed this was a native VS Code button that showed up when you had a language debugger installed. When I removed all extensions, except the Microsoft Python extension, I was convinced this was part of VS Code.
The answer above incorrectly states that this is the correct behaviour for the button. It is not. Microsoft has confirmed this and if you read issue #2338 ("Documentation for python.terminal.launchArgs is unclear") there is a response in there stating:
"Unfortunately that's just how vscode works. When debugging all settings are read from launch.json and non-debugging settings.json is used
This applies to all languages (extensions) in vscode."
So for now, there is nothing much to do other than wait for this to be fixed.
Lastly, for those who are wondering why I wanted to use that button in the first place. For the most part, I use keyboard mappings to start debugging when I am inside VS Code. But for this particular project, I was going to other external windows and when coming back to VS Code, since I was already using the mouse, I just wanted to click there out of convenience. I don't keep the debug tab open which also has a debug button that works as intended.
Related
For some weird reason, Visual Studio hasn't performed correctly what I've been doing in python. Unlike all the tutorials I find, where they normally run in the "output" field, in mine it displays correctly only in the terminal.
print('test','trying', sep='#')
Output:
File "/Users/x/Desktop/Livre.py", line 2
print('test','trying', sep='#')
^
SyntaxError: invalid syntax
Terminal:
test#trying
Here is an example of the SEP command, but the same thing happens, for example, when I put special characters in lists, even when I use utf8.
Does anyone have an idea why this is happening?
EDIT:
So, I understood what is happening, like was told in one of the answers: Visual Studio Code is using python version 2.7 in the "Output" field, for some reason, even though I have installed and reinstalled Code Runner and Python 3.10 several times.
Unfortunately so far it hasn't solved the problem.
But I haven't given up yet, and somewhere here in Stack I wiil discover how to figure it out :)
Install and run the code with Code Runner.
After installing this extension, the triangular play button in the upper right corner will have three options
Select Run Code to run the code, and the result will be output in the OUTPUT panel.
Right-clicking directly on the editor interface and selecting Run Code is the same.
Tips:
Among the three options, Run Code is provided by Code Runner, and the other Run Python File and Debug Python File are provided by Microsoft's official extension python.
Im really quite new to coding and brand new to Python so apologies if this is a dumb question.
I'm writing basic scripts in VS Code and when I run them the result in the terminal is just..... ugly. Instead of just printing the result of my code, it prints details about my version of Windows, a little copyright notice, the full file path to my code... then eventually gets round to executing my actual code.
Is there any way for me to configure the terminal so that it just shows my code and not all the other bits? I've already seem about an extension called Code Runner, but this prints to the "Output" tab and doesn't allow any user input
If you are using PowerShell, you can add "args": ["-NoLogo"], like this to Hides the copyright banner at startup :
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"path": ["C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"],
"args": ["-NoLogo"],
}
},
And you also can change the value of console in the launch.json file. But internalConsole does not accept the user input. And externalTerminal will prompt a cmd window out of the VSCode.
Maybe you can try Jupyter code cells:
https://code.visualstudio.com/docs/python/jupyter-support-py
Try jupyter on visual studio code interface
https://code.visualstudio.com/docs/datascience/jupyter-notebooks
You have to follow these steps:
install python extension for vs code.
python extension
2.After installing reopen vs code and you will see a play button at right-top corner.
play button
3.Click that button and run your code!
go to settings
search for terminal
find Code-runner : Run in Terminal and turn that off.
I'm trying to learn Python and if you look 5-7 minutes into this tutorial he's able to - in a very illustrative way - debug (or "follow") his code. I'm unable to replicate this in a similar way in Vscode.
https://www.youtube.com/watch?v=akcEaEH91gI
Is it not able, or is it done in another way?
If you look at my screenshot. Nothing is added inside the script-console or the debugging console - as in PyCharm. Meanwhile, I get some data to the left but it's not as illustrative.
https://i.imgur.com/1J6N138.png
Not bashing Vscode, just trying to learn. :) Thanks
For the requirements you mentioned, please refer to the following:
About viewing variables.
In VSCode, we can view the variables in the code in the following two places:
1). "VARIABLES" on the left side of "Side Bar":
2). Right-click the mouse and click "Run Current File in Ineractive Window":
About "DEBUG CONSOLE".
When we use the setting "console":"internalConsole" in "launch.json", the execution result of the code will be displayed in "DEBUG CONSOLE", and VSCode will output in "integratedTerminal" by default.
In addition, since they are different software, we can't require them to be exactly the same in use. But if you encounter any usage and technical problems when using VSCode, please let us know.
More reference: The use of VSCode.
I have downloaded python package from the web (e.g., github).
The usage is via CLI, for example:
python functionality.py opt1 opt2
Since I want to understand what is going on under the hood in functionality.py
I want to be able to debug it line by line.
How can I achieve that using PyCharm?
Sorry for not writing a comment, but I don't have the right.
You could use the package in a simple script (import it). Afterwards, press CTRL+LEFT CLICK on the function/class that you have used in order to see the source code. Now you can put breakpoints my clicking on the space near the line number. The red point indicates that a breakpoint is put.
You can run your script in debug mode using the debugger from the menu up right (second icon) and see what's happening.
I am programming python 3 with Microsoft Code.
When I press "F5" to start the programm I always get a menu with the following selection:
Python
Python Experimental
More
to select the execution environment.
However, I directly want standard python to be run, when pressing F5.
I have googled a lot and already checked the configuration of Microsoft Code (there is only one python installed and selected) but did not find a switch to switch "Experimental" off.
Many thanks for your help!
Happened to me once. Seems like the Python Debug Configurations didnt load correctly.
After reselecting my Interpreter I was able to select the Debug Configuration "Python: Current File" again and run it without prompting me to select a Config.