I am new to Python and Visual Studio Code. When I try to use the input() statement and run the code, the terminal window shows the prompt which I have included in the statement but does not show a curser after the prompt where the user should type in the input. I need to mouse click in the terminal window after the prompt and then press enter for the input to be accepted. This doesn't seem right. Any ideas?
If you run a python script in an IDE, it will fire up an integrated terminal and will execute the program by doing something like python <your_file_name>.py.
This process isn't supposed to change the IDE's focus to the terminal. Because often times, developers like to have their editor in focus even though their program is running in the terminal. And hence VSCode is developed to behave this way. You can see this exact behaviour in many modern IDEs.
I've been running some simple python scripts in Pycharm as I develop an app. The below described problem happens with every app within this project, while in other projects I'm not seeing this.
When I run the script, even if it's just a simple
print('Hello World.')
I do not get an exit code. It looks as if I am running the program from the Python Console, but I'm running it by right clicking on the script and choosing run.
I can rerun the script without issue, a new tab just opens in the python console window with an incremental (n) next to the filename.
What I end up doing is clicking on the red stop button which is when I do finally get the exit code. I then close the tab and move on.
In your "Run/Debug Configurations" choose "Emulate terminal ..."
Select emulate terminal in debug configs
I recently started using PyCharm with Powershell as terminal shell, however I am experiencing problems with keyboard shortcuts. While terminal screen is active, 'ctrl+c' should interrupt current command, but it is not. Also 'ctrl+end' should clear current line, however this shortcut also is not working.
Is there any way to make PyCharm's terminal properly react to PowerShell's keyboard shortcuts?
What I would like to do is launch an interactive ipython session from notepad++, and keep the window open (in interactive mode) after a script completes, but for the window to close once I exit from ipython. This seems like a fairly simple task, but I'm having trouble finding the answer.
In notepad++, I have entered the following for the Run command (F5):
cmd /k ipython -i "$(FULL_CURRENT_PATH)"
This works fine: it opens and runs the script I am editing using ipython, and keeps the ipython session open once the script is complete.
However, after entering the exit command, I have to enter exit a second time at the command prompt) to close the window (or close it with the mouse). It would be nice if I didn't have to enter exit twice. Is there a solution to get things working the way I want them to work?
I have tried removing /k flag (my understanding is this flag keeps the window open):
cmd ipython -i "$(FULL_CURRENT_PATH)"
However, the script does not seem to run at all in this case.
Well I discovered the answer just before I was about to post the question! Instead of deleting it altogether, I thought I would go ahead and post the resolution so that others can find it later. It turned out to be pretty simple!:
ipython -i "$(FULL_CURRENT_PATH)"
(Note that in order for this to work, ipython must be available as a program to be run from a command prompt.)
I am running python 2.7.1. I can't figure out how to launch the IDLE IDE. I am told it comes already installed with python, but I can't find it using spotlight.
In the stock Mac OS X python installation, idle is found in /usr/bin, which is not (easily) accessible from Finder and not indexed by Spotlight. The quickest option is to open the Terminal utility and type 'idle' at the prompt. For a more Mac-like way of opening it, you'll have to create a small app or shortcut to launch /usr/bin/idle for you (an exercise left to the reader).
When you open up a new terminal window, just type in
idle
Then you will see a little rocket icon show up as IDLE loads
Then the Python shell opens up for you to edit
I think the shell command is
python -m idlelib.idle
but i am not a mac user so i can't test.
One way to run IDLE from spotlight or an icon in the Applications folder is to build a quick Automation for it. As mentioned by other commentators, this probably isn't necessary for Python 3, as it creates a shortcut automatically, and some hand-installed versions have tools to do this automatically. But if you want to roll your own:
You'll need to know the terminal command to open your version of IDLE. On my Mac right now (early 2016), running python 2.7.10, it is "idle2.7"
Using spotlight, or in the Utilities folder, open "Automator"
Choose an "Application" type document.
Make sure "Actions" is selected in the gray bar, upper left.
In the actions column, find "Run Shell Script" and double-click it, or drag it to the workflow area on the right.
Enter the terminal command in the parameters box that appears.
Save your automation (I called mine "IDLE" and put it in the Applications folder, to make it easy).
It's now available (as soon as spotlight indexes it) via all the normal methods. The only side-effect will be that while it's running, your menu bar will have a spinning gear over in the tray area next to the clock. This indicates an automation workflow is running. Once you close IDLE, it will go away.
first to launch the terminal CMD+space
second to input idle3
the idle will be activated automatically.
After you launch idle from the command line (make sure idle shell window has focus), click File, click "New File". A new window opens; this is your editor.
Type your program in the editor. Click "File", click "Save As...". Save your file somewhere with any name you choose, and a ".py" extension to the file name.
Click "Run", click "Run Module" (or, F5). Assuming no errors, the results will appear in the Shell window. Edit your file & repeat as necessary.
The answer of Matthewm1970 works like a charm!
And if you add an & to your shell command, the automation script will end immediately. There is no spinning gear. Like so:
/usr/local/bin/idle3.5&
Note the ampersand.
Cheers.
-melle
open Terminal
type "idle" and press enter
right click on "Python" icon > Options > Keep in Dock
so for python 3.4.3 in applications a folder named "python 3.4" click that and click IDLE.
for python 2.7.9 go here https://www.python.org/downloads/ and get 2.7.9 and a folder named "python 2.7" click that and click IDLE.
As to the earlier questions about starting IDLE: you can certainly start it from the command line. Also, if you installed Python using Homebrew, you can run 'brew linkapps' (from the command line); that will place an app for IDLE (among other things) in Launchpad (Applications folder).