How to debug from cmd on vscode - python

I don't know how to debug a code from Windows cmd. Bcuz my terminal (in vs code) is pixelated and I don't know what to do about it. By the way, I tried everything such as changing terminal font and font size.

First create a launch.json file for your python project
then use the play button in the picture to start debugging the code.
You can configure how to debug in more detail in the launch.json file.

Related

Change the version to Python 3 in Virtual Studio Code (VS Code) if Code Runner uses older version like python 2 (Q+A)

I use the extension code-runner for my VS code to run it directly in the app without a terminal and I had a problem where I had the latest version of Python installed (3.10.0) I had selected that version as my interpreter yet code-runner was running my code in python2.
Here is the solution which worked for me:
As a beginner, I could not understand the way other solutions were explained so I hope this helps:
Go to your User Settings .json by opening the Command Palette with View > Command Palette or by pressing Command+Shift+P on Mac or Ctrl+Shift+P on Windows. Then search for Preferences: Open Settings(JSON)
in a new tab, once again open the command palette but this time look for
Preferences: Open User Settings
in the 'Search settings' bar at the top search for 'Shebang'. Make sure that the box of 'Code-runner: Respect Shebang' is not ticked.
go back to your .json settings file and check that the following line of code is in there:
"code-runner.respectShebang": false,
if not, first reload the page, searching for Developer: Reload window in the command palette.
if it still isn't there you will need to add it yourself alongside all your other settings like so:
You will need to go again to Preferences: Open User Settings in the command palette and in the settings search bar look for Code-runner: Executor Map. If it is not in your settings.json file then you will need to press the little settings/gear icon which pops up when you hover your cursor over it and then select 'Copy Setting as JSON'.
Go back to your settings.json file and paste it in there alongside all your other settings like with Shebang.
it should look something like this:
My problem was with python (but this applies to any other language). Go to the line "python": "python -u", and change it to "python": "python3 -u",.
This solved the issue for me. :)

VSCode: Code Lens for Jupyter Notebook does not show debug option or "run code by line"

I am still new to vscode, but I am having trouble getting some of the tools for python Jupyter notebooks to work in VSCode Version: 1.56.2 on ubuntu linux 20.04 LTS.
So according to the documentation, there are supposed to be buttons for debugging, including a button to "run code by line". This makes it easier to debug any code issues in a notebook cell. The documentation suggests the notebook interface should look like this.
The buttons in the upper left are the ones that I am interested in.
Now, when I look at my own interface, it looks like this.
So the two interfaces look very different. I am not sure if I need to change any settings in VSCode to enable these buttons. The documentation did not mention changes to any settings.
Any suggestions would be appreciated.
"Run code by line" has not yet been implemented for the new notebooks interface that you are seeing. In the meantime, you can opt back into the old interface with "Run code by line" support by doing the following:
Open your user settings.json by typing Ctrl+Shift+P > "Preferences: Open Settings (JSON)"
Add the following line to your user settings.json file:
"jupyter.experiments.optOutFrom": ["NativeNotebookEditor"]
If the workbench.editorAssociations setting is present in your settings.json file, delete it.
Reload VS Code for the new settings to take effect
In vscode 1.59 (see https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_59.md#jupyter-run-by-line)
Jupyter "Run By Line"
We've been working on supporting the "Run By Line" feature in Jupyter
notebooks. This feature is essentially a simplified debug mode that
lets you step through your cell's code line by line without any
complex debug UI. This is still experimental, but you can try it out
by setting "jupyter.experimental.debugging": true, installing
version 6 of ipykernel in your selected kernel, then clicking the "Run
By Line" button in the cell toolbar.
"jupyter.experimental.debugging": true
Of interest
We have been working on supporting debugging in Jupyter notebooks, so
that you can set breakpoints in notebook cells, execute cells
step-by-step, and use all other VS Code debugger features. This is
experimental, but you can try it out by setting
"jupyter.experimental.debugging": true, installing version 6 of
ipykernel in your selected kernel, then clicking the "Debug" button in
the notebook toolbar.
in vscode v.158, https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_58.md#jupyter-notebook-debugging
Make a debug point and just press F10 ; Debug will started automatically

How to automatically clear terminal in Visual Studio Code when running the file on terminal?

is there a way to configure VS Code to automatically clear the terminal right before I run a Python file, for example? I searched a lot for that but without success. Whenever I try to run a file in terminal, previous runs are still there in the terminal, and it gets kinda confusing. Notice that I want to clear the terminal when I run the code in terminal (i.e. when I click the play button), not when I run with debugging. My idea is to always have the terminal empty when I run a file. Any thoughts?
Currently in VS Code, it does not automatically clear the terminal data settings, but you could use the command "clear" in the VS Code terminal to clear the previous output data, or click the'kill' icon to delete the current terminal and use the shortcut key Ctrl+Shift+` to open a new VS Code terminal.

How to disable stopOnEntry for files that are opened without a workspace?

When I open a python file without a workspace and start debugging it, the debugger breaks on the first line. I would like to change this behaviour, but I don't know how to do it for files that are opened without a workspace.
Open launch.json (gear icon when on debugger tab). Find the section for the python debugger you are using. Change "stopOnEntry" from true to false. Save.

Lost My "Output" Window

I am sure I am using incorrect terminology, but hopefully you can grasp my meaning. I am working with Spyder python 2.7, and I have somehow lost my "output" window. I attached a screen shot. Formerly, there was a window, that, after having run my code, gave me the results of my code. How do I get this window back? I went to the view options, but had no such luck.
(Spyder dev here) You have two options to make your console back (that's the right name of what you called as output window :)
Go to the View Menu and there from to Windows and toolbars and select either Console or IPython console.
If this doesn't solve your problem, just open a Windows terminal (i.e. cmd.exe from the Start > Run Window menu) and in it run this comnmand:
spyder --reset
and then restart Spyder again. That should solve your problem for sure.

Categories

Resources