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.
Related
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.
I was using a different IDE for running Python scripts, but I would like to switch over to Visual Studio. When I try testing simple scripts that work in the simple IDE, I can't figure out how to get my output to show correctly. I have tried running the debugger, pressing CTRL+F5, and pressing CTRL+F5 then CTRL+d, but all that happens is that a blank console pups up, and the cursor blinks actively.
I have run out of ways to rephrase this issue to get something helpful to show up in both Google search results and in StackOverflow. The main results I get are about antivirus software (thoroughly investigated, not the problem here) and articles about beginning Python in VS. How do I get my Python programs to show output correctly? And also am I using incorrect terminology?
What happens when I hit Ctrl+F5
Have you already gone through the Installation, Quickstarts and Tutorials here:
https://learn.microsoft.com/en-us/visualstudio/python/overview-of-python-tools-for-visual-studio
Make sure the simple hello_world.py file with one line works:
print("Hello World")
If you still have problems, it may be that Visual Studio does not realize you have Python installed (i.e. if python is not in your path variables).
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.
I installed VSCode, downloaded official Python 3.6.4.
VSCode detected and set the environment right - I do see "python.pythonPath" user setting set correctly.
But, when using VS Code using Ctrl+F5to run a Python file, I am always getting asked for "select environment" and it shows me two options
- Python
- Python Experimental
What is this "Python Experimental"? How can I get rid of getting interrupted every time I try to run a script?
Run > Add Configuration... => Choose one of the two options.
After doing this it will no longer prompt you.
Ctrl+F5 is a shortcut to Start without Debugging What you want is just running a file according to your post. To run a python file in the integrated terminal, right-click your editor window and Run Python File in Terminal. It should open up a terminal window within VS Code and run as normal. It also takes into account the environment you are currently using whenever you run it.
To answer your other question about Python Experimental, it is an option to use the experimental debugger, an alternate version of a Python Debugger. You can read the instructions here
I have installed Python Tools for Visual Studio and I cannot see the output in the console window like I see output when I run a C# console application within visual studio upon hitting the following Shortcut keys.
F5 -- Starts debugging the program and closes the console window in c# and in Python
Ctrl+F5 -- Start without debugging, works as expected in C# but not in Python program. It always exits the console window under both the options.
There is a third option "Execute Project in Python Interactive" for a Python Application. This option sometimes produces output and sometimes does not.
What should I do to see the output in the console window and the windows should not close after running the program? Is this even possible or some conceptual difference for python console apps?
Am I doing something wrong here?
There's an option in Tools->Options->Python Tools->Advanced under the Debugging section for "Wait for input when process exits abnormally" and "Wait for input when the process exits normally". I thought they were supposed to be on by default but enabling them should cause it to wait.
for future visitors from google. This doesn't involve Python settings, but to prevent the console window from closing automatically while using "Start without debugging" (Ctrl + F5). Try looking for this setting.
Project -> "project name" Properties -> Configuration Properties -> Linker -> System
Then look for the SubSystem property, and set it to
Console (/SUBSYSTEM:CONSOLE)
You can select it via drop down or try and type it.
if you have trouble seeing it under System you can also check under All Options
Hit save and then it should work immediately. Confirmed this works on VisualStudio 2013, but I also think it works on other versions too.
UPDATE: Visual Studio 2017 - the items listed have moved :-( and I don't know where they moved to