Debug with internal command window Python Tools and Vistual Studio 2013 - python

I just installed Python Tools with Visual Studio 2013 (Shell) and whenever I run a debug of the program, a separate window pops up for the interpreter:
I can however run the program using the internal interactive console:
However this doesn't seem to stop at any breakpoints that I set in the code. Is there a way to force the system to use the internal console for debugging instead of using a separate windowed console?

You can hide the shell by changing Environment options in Python Tools with Visual Studio, change the default path to point pythonw.exe.
Here is the steps:
TOOLS -> Python tools -> Python Environment
Open Environment options, Add Environment, Enter whatever you want to name it.
Copy all the options in the default Environment except change "Path:" to path of pythonw.exe. Hit OK and made the new Environment as the default environment.

There's no way to hide the console window entirely, but all output from it should be tee'd to Output window, so you can use that if you don't like the console.
There's also a Debug Interactive window (Debug -> Windows -> Python Debug Interactive) that you may find of help, if what you want specifically is being able to stop at breakpoints and then work with variables etc in a REPL environment. Once enabled, this window will provide you a live REPL of the debugged process, and when you're stopped anywhere, you can interact with it. Like Output window, it does not suppress the regular console window, but it mirrors its output.

Although this seems old, solution pasted elsewhere can help someone searching an answer.
I cannot comment since I don't have rep.
Here is the solution: https://stackoverflow.com/a/22486749/4809808
As far as the console window it will generally open unless you mark your app as a Windows application in project properties (this will launch pythonw.exe which doesn't include a console window).
If you right click on your project and choose Properties in the "General" tab there's a "Windows Application" checkbox below Working Directory.

Related

PyCharm running Python file always opens a new console

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

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.

How to run same application in new run tool window? Pycharm Community 2017

I am working on a Python 3.6 project in Pycharm Community Edition 2017.2.3.
I have multiple run configurations in my project. Each different run configuration will open a different 'Run tool window'.
I want to look through the output of the previous run of my application while re-running it in another tool window. However, each new run of the same configuration will overwrite the console output of the previous run. How do I run the same application/configuration in a new tool window?
It's probably possible to just duplicate the configuration, but I'm looking for a better way. Maybe something similar to opening new terminals?
Go to build configurations and enable show command line afterwards.
It simply opens the python interpreter in the console after running your code.
Now When you run the code again. It will open a new tab in the run window, instead of overwriting the old one.
You can pin first tab by right click then run another script
I do not think if it is possible. But you can do it using terminal.
It's still in Run/Debug configurations but now it's called, "Run with Python console".

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)

Console windows closes right after I hit ctrl+F5 in visual studio tools for python

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

Categories