In vscode using Python, ctrl+F5 always asks for "select environment" - python

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

Related

my code is not showing is the terminal and there is no error

I was trying to run a code in vs code but the code didn't run and there is no error showing in the terminal. I made a new file and then tried to run a "Hello World!" but the code didn't run too. I uninstalled and re-installed vs code (three times) but that didn't work.
And when I say that there is no error showing I mean it. whenever I run the code nothing happens and vs code doesn't even give a hint or a sign that the code got executed or not.
First, you should understand that vscode is a lightweight editing
tool. If you want to run python files, first make sure you have
installed python correctly. You can enter command python --version
in the terminal to confirm it.
Then, please install python extension in the vscode extension store.
Then use shortcuts "Ctrl+Shift+P" and type "Python: Select
Interpreter" to choose the python interpreter.
Finally, creat *.py file and run it.
Read this docs for more details which can help you get started faster.

Cannot run Python Script inside VSCODE terminal

However simple my python script is, I cannot get it running inside VSCODE Terminal by clicking on the "RUN" icon at the top right, whereas it runs fine when called from a CMD window
I had the same problem, this thread helped me I get a syntax error about File "<stdin>", line 1
You are now working inside your Python shell (>>>) while the code you are running (& python "FILENAME.py") is no Python, therefore syntax error.
exit()
to exit the python shell and return to the PowerShell environment.
Simply
python
to enter again, to run python code directly
It seems python is not recognized in your PATH variable. I think the 2 ways to fix are to find your python filepath and adding it your User Variables:
Control panel > System > advanced settings > Advanced tab > Environment Variables
select PATH and then click edit..
in a new line add the path to your python installation (ie C:\Users\YOURUSERNAME\AppData\Local\Programs\Python\Python38-32)
OR, not sure this works out of the box but you could:
install Python module from within VS Code, published by Microsoft
After editing the PATH as suggested by #mah111, I needed to restart VSCODE application

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

Python with Visual Studio Code - How to deactive "Python Experimental"?

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.

Python curses Redirection is not supported

I am trying to use Curses in PyDev in Eclipse in Win7.
I have installed Python 3.2 (64bit) and curses-2.2.win-amd64-py3.2. When I input the following testing codes into PyDev:
import curses
myscreen = curses.initscr()
myscreen.border(0)
myscreen.addstr(12, 25, "Python curses in action!")
myscreen.refresh()
myscreen.getch()
curses.endwin()
It did not show any syntax error, so I think the curses was installed correctly.
However, when I ran it as Python Run, the output showed: Redirection is not supported. I do not know where this problem comes from. I googled a lot but can't find related information.
Recent PyCharm versions (I am currently running 2017.2, not sure when this option was added, or if it has been there the entire time) have the option "Emulate terminal in output console". Curses works with this option checked.
You cannot expect to use curses with a non-terminal.
Probably you get this because you are running the script from inside an IDE, like PyCharm or any other.
All IDEs do provide consoles that are not terminals, so that's where the problem comes from.
For a Pycharm user the solution given by codeape works fine :
Snapshot
You can't use any IDE to run python files with the curses package. I used to run in pycharm and naturally couldn't run.
Change to the command line to run:
for testing follow my following steps
on desktop open notepad and copy paste the code and save it as filename.py
open command line change directory to desktop use below command cd Desktop and hit enter type python example.py and hit enter, your program will definitely run
My workaround is to create a Run Configuration that calls a curses script. The little overhead is worth not having to switch to the terminal and manually run the script hundreds of times a session. I use Intellij but I imagine the process should be similar in PyCharm.
The desired result is the convenience of a button to run the script:
First create a script that calls the entry script, for instance:
ptyhon name-of-script.py
Then, to create a configuration for each script:
Go to Edit configuration.
Click the plus button and add a Shell Script.
Enter the path to a shell script.
Here is a picture of a directory with a couple of sample scripts.
I use this process to view my progress. My curses scripts are very modest so fortunately I can live without a debugger.

Categories