Code Runner Icon not showing in Visual studio code - python

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.

Related

Vscode will not autofocus on integrated terminal while running code

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.

Running Python in VS Code Terminal

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.

CodeRunner Setup in VSC for Python

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.

Visual Studio Code is not showing the ouput of Python

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.

A very basic setting issue about spyder and anaconda for python

I am a beginner of spyder IDE for Python.
To use spyder IDE, I command "spyder" on anaconda console with python 2.7
After that, I try to print "hi"
But I encounter an error message
"No python shell is currently selected to run hu.py Please select or open a new Python interpreter and try again"
How could I solve this problem?
I saved my file on C:\Anaconda\practice_jhk
from __future__ import print_function
print ("hi")
You can specify the Spyder's Run Settings in Run -> Configure (F6). By default "Execute in current Python or IPython console" is selected and you probably do not have any open console in Spyder.
You can select "Execute in a new dedicated Python console" option and Spyder will automatically open a new console for you. Or you can leave the dafault option and create a new console yourself in the Consoles menu.
I have had the same problem. I am not able to fix it but I am able to successfully run the program the following two ways and I don't find any problems till now:
By selecting IPython console (not the one with the Kernel id as its tab) then running your program.
By selecting "Execute in new dedicated Python console" from Tools --> Preferences --> Run.
I was getting the same error message, but then realized I was not directing the PATH to my Python interpreter file at all. How I solved the problem:
Go to Tools > PYTHONPATH manager
Select "Add path"
Find and select your Python interpreter folder (for me this was C:\Python27)
Try, tools -> Reset sypder to factory default. Then, click on the run button in the dialog box.
I had this issue when I didn't have the python console pane open.
To resolve this, in the top bar go to: view -> panes and turn ipython console on.
This fixed it for me.
You might have unexpectedly closed the Ipython console window which is open by default and that caused the error.
Go to Consoles > New console(default settings)

Categories