When I run without debugging in python on vscode it no longer autofocuses on the terminal forcing me to click into the terminal everytime to input data. Is there any solution to cause vscode to autofocus when code is running?
I think there is no relevant implementation method for code runner at present. You could use shortcut "Ctrl+~" to foucus on the terminal, and I will submit the function to GitHub.
Two Fixes/Workarounds I utilized.
Autohotkey Script:
F9::
Send {F5}
Sleep 200
SendInput ^{~}
Or Rebind:
View: Toggle Terminal Originally (Ctrl + ~) to F5 so jumps to the terminal everytime you run
The following solution to this issue has been tested on Visual Studio Code 1.74.3.
Install the Python extension for Visual Studio Code.
Go to File >> Preferences >> Settings.
In the Search settings field enter, "Python › Terminal: Focus After Launch"
Click on, When launching a python terminal, whether to focus the cursor on the terminal.
A check mark should appear in the tick box.
Done! Now every time you Run Python File the terminal will be focused.
Related
I can run a python script by pressing the run python file button:
but unable to run the same when pressing the F5 key or run from the dropdown menu.
I can also run in the interactive window fine:
And likewise i can run a notebook fine.
other checks:
I can verify that it doesn't debug by adding a breakpoint and running.
Would there be a key-binding that is missing perhaps ?
What is causing this and how can one fix the issue please ?
It turns out that the error is a bug in the Python extension.
If you go to the Extensions tab, select the Python extension, then click on the little arrow next to Uninstall > Install Another Version... and install 2021.12.1559732655 the debugger should work again.
Here is the link to the fix: https://learn.microsoft.com/en-us/answers/questions/724858/vscode-debugger-not-working-for-python.html
In the meantime disable automatic updates to make it stick until they fix that.
To do this going to settings, typing python.terminal.activateEnvironment into the search bar and deactivating the checkbox.
I've installed VSC and added to it the C/C++ and CodeRunner extensions, and it all worked perfectly. I've set CodeRunner to run in Terminal and I haven't done much else to the settings.
However, I installed the Python extension now, and the CodeRunner 'Run' button displays 2 options when I click it: Run Code and Run Python File in Terminal. When I was running a C program previously, one click on 'Run' would do it.
Is there any way to eliminate the extra options when running Python code? Essentially, I just want the program to execute with one click on 'Run'. Seems like the code executes regardless of the option I choose. (See the attached picture). Thank you.
Reason:
In VS Code, the green run button provided by the "Python" extension is to execute the command "Run Python File in Terminal". It only requires us to click once to run python files in the Terminal of VS Code:
When we also use the extension "Code Runner", the run button ("Run Code") provided by it defaults to output results in "OUTPUT". In the previous use, this button will cover the green button provided by the "python" extension, but now that they are integrated, we can choose the execution method.
For setting "code-runner.runInTerminal": false, it determines whether the "code runner" runs in the "Terminal", the commands they execute are different:
"Run Code":python -u "/python_file.py"
"Run Python File in Terminal": /python.exe /python_file.py
Solution: You could use F5 to debug the code or try to close the "Code Runner" extension. (Click "Enable" to restore the use of the extension.)
Reference: Run Python File in VS Code.
Today i opened my vscode editor and i saw that the code runner icon had disappeared despite that it was installed. I could only see the default run code option. Please help me solve it, I also tried uninstalling and installing the extension again and also did the same with vscode but the problem still persists![the run option os of default vscode not coderunner][1]
Go to the extensions and then search for code runner after this install it and then it will appear.
This button does not disappear, but is integrated with the original "Run Python file in Terminal" button in the Python file. Click this button and it will display two run options: "Run Code" provided by Code Runner extension and "Run Python file in Terminal" provided by Python extension.
Check the pyhon ... program language version and select the correct one if you are using several different versions.
I initially started learning Python in Spyder, but decided to switch to PyCharm recently, hence I'm learning PyCharm with a Spyder-like mentality.
I'm interested in running a file in the Python console, but every time I rerun this file, it will run under a newly opened Python console. This can become annoying after a while, as there will be multiple Python consoles open which basically all do the same thing but with slight variations.
I would prefer to just have one single Python console and run an entire file within that single console. Would anybody know how to change this? Perhaps the mindset I'm using isn't very PyCharmic?
There is a specific option in PyCharm 2018.2+: Settings | Build, Execution, Deployment | Console | Use existing console for "Run with Python console".
Run with Python console is an option you have enabled in the Run Configuration. Disable it if you don't need a Python console after a script execution:
Hi: If you are looking for re running the code again in the same python console everytime then you have to check the respective box in the Project settings as shown in image below.
To allow only one instance to run, go to "Run" in the top bar, then "Edit Configurations...". Finally, check "Single instance only" at the right side. This will run only one instance and restart every time you run.
One console is one instance of Python being run on your system. If you want to run different variations of code within the same Python kernel, you can highlight the code you want to run and then choose the run option (Alt+Shift+F10 default).
You have an option to Rerun the program.
Simply open and navigate to currently running app with:
Alt+4 (Windows)
⌘+4 (Mac)
And then rerun it with:
Ctrl+R (Windows)
⌘+R (Mac)
Another option:
Show actions popup:
Ctrl+Shift+A (Windows)
⇧+⌘+A (Mac)
And type Rerun ..., IDE then hint you with desired action, and call it.
I think that what you are looking for is the last option in this window; check it and it should work.
Settings -> Build, Execution, Deployment -> Console
I am really new to Python and just started the course "Python 3 basics by Sendtex (Link: https://www.youtube.com/channel/UCfzlCWGWYyIQ0aLC5w48gBQ)".
I am trying to use Python with Visual Studio Code.
The downloaded version of Python is 3.6.4.
I have installed the Python extension in Visual Studio Code and have followed the procedure.
However, I am not able to get any output. Below is the attached screenshot.
If I select Python it enters debugging mode. So, there isn't any output.
Using the Python Extension Run/Debug commands
Notes
I recommend reviewing the official Visual Studio Code Python documentation and tutorial. That provides several of the basics, with running and debugging the "official" way.
There are multiple ways to configure built-in launches:
When running or debugging Python in VS Code, there are a few options that you can change in your "launch.json" file. See this answer for more details.
Run or Debug with the built-in Python extension commands
You can run or debug using the "triangle" icon and dropdown in the upper right of your editor window, when the editor window is focused on a python script file (i.e. typically a file named *.py).
You may need to setup a run/debug configuration to use this (see below), or it may automatically step you through creating one.
The output will normally go to a new "Python" terminal in the "terminal" window (Ctrl-`, to open it). See this answer for how to change that behavior.
Setting up a run/debug configuration
Easy option:
Use the menu item **Run/Add Configuration, and follow the prompts at the top of the VS Code window.
Some of the additional details are shown below.
More involved option:
Click the run/debug icon on the left vertical icon toolbar.
The window says "RUN AND DEBUG" at the top, with a drop-down that shows "No Configurations" for a given folder or workspace until you set this up.
The gear to the right of the dropdown will have a red dot if you need to configure this:
Updated Image (1/2022) - Changed from just 'Debug' to 'Run and Debug':
Click the gear icon (or in the menu, use Run/Open Configurations), and in the middle at the top, Visual Studio Code will open a window titled "Select a debug configuration".
The available options will depend on exactly how you have Visual Studio Code setup and configured
There should at least be a "Python File" option with the Python extension installed. Select it.
Now your debug configuration box on the top left of the debug pane should say "Python: Current File":
Visual Studio Code will add a file to your current workspace or working folder called .vscode/launch.json, and opened it for edit.
During installation if you forget to tick in check box for path and then if you are running any python file on visual studio it will not return any output untill and unless you have not added it into visual studio code.
First of all go to File → Preference → Settings.json
"code-runner.executorMap":
{
"python": "\"C:\\Program Files\\Python39\\python.exe\""
I have attached the screenshot for your better understanding!
Simplest Answer: Run the file directly in a terminal
Open a terminal in VS Code (View/Terminal in menu or Ctrl-`, which is the "Ctrl" key and the "Grave" or "Tick-mark" key, normally at the top left of keyboard above tab).
This will open the terminal to the root of the folder VS Code has open (the one that shows up in the Explorer sidebar - Ctrl-Shift-E to see).
Run the python script in the current directory with a simple python my_script.py command.
If the script is in another directory than the root of the current workspace or folder you opened the terminal in, you will need to change to that directory (using cd commands, etc.), or add the absolute or relative folder path to the name of the script.
The output will show up in the same terminal.
Notes
You must have a python executable on your path, be in an active virtual environment, or give the full path to the python executable.
Your python command may be python2 or python3 on some installs (usually linux), and can be just py for the Python Launcher (auto-installs with typical Python for Windows installs).
This option will not use any 'launch.json' configurations, and cannot be easily used to debug with.
You can configure the default terminal that is used, such as Git Bash, CMD, or Powershell (on Windows). You can also open additional terminal windows of any configured type using the "+" icon and it's dropdown, in the terminal window.
I found this post when trying to find how to show my python code output in the VSCode output window instead of the integrated terminal window. In my case the problem was caused by a Code-runner setting. Here's how I fixed my problem :
Open Command Palette(CTRL + SHIFT + P).
Search and select Preferences : Open Settings (UI).
Search the following setting : Code Runner : Run in Terminal.
Untick the box.
Now when you select Run Code (or CTRL + ALT + N) option when running your code, the Output window should work.
Note
The integrated terminal will not show code output now.
The output window in VScode is read-only. My method is not suitable if you are taking input from user.
I had the same problem, but figured that close to top right of your Visual Studio Code there is a little green triangle saying "running code in Terminal".
I you wanted to see some kind of print('Hello') it is does the job.
I ended up scrapping code and moving my project to Visual Studio 19. Works just fine now. Prints show up in a command prompt.