What Terminal does Python IDLE use on Windows - python

I was helping a fellow Stack Overflow-er today and I noticed that I don't know what terminal IDLE uses in Windows. I am tacitly assuming that Python didn't write their own terminal for Windows, and that they probably use an API that gives them some version of cmd or powershell. I verified that the interpreter runs on cmd, but I don't know about IDLE.
What terminal does IDLE use in Windows?

IDLE is not built on an external shell or terminal, but on the Tkinter GUI toolkit.
The source code to the editor window can be read here; for the interactive shell, see here.

Related

Is pythonw exe an "external" application

Using Python 3.10:
import os
os.system('notepad.exe')
Notepad launches, but if I try that with pythonw.exe Idle doesn't launch but the exit code is also 0.
Not sure why. Is it because pythonw is not an external application? How can I launch IDLE from the interpreter?
I apologize, not sure how to include code properly....
Many thanks
pythonw is not IDLE. pythonw is just another copy of python that is marked as a Windows GUI application, so it doesn't attach to your terminal session. IDLE is a separate command. Depending on where your Python installation is, you can run:
C:\Python310\Lib\idlelib\idle.bat
Or, even easier:
pythonw -m idlelib

open terminal window with python

On Windows, the python subprocess command to open a cmd window is simply:
import subprocess
subprocess.Popen('cmd.exe')
Can anyone tell me what the command to open the cmd equivalent in Linux is?
I'm going to be copying some python code from my Windows machine to my Raspberry Pi and am new to Linux - I know that this line of code won't open the terminal on a Linux OS the same way it will on Windows.
Thanks in advance!
Replace cmd.exe with gnome-terminal in order to open a terminal on Linux
Different distros use different terminal programs. xterm should work on just about everything, so you could Popen('xterm') and then require the people figure out how to get xterm on their system if its not there by default.

Pyinstaller on Linux - How to show a console

I'm trying to generate a Python executable file with Pyinstaller on Linux. For this purpose I'm trying this implementation with a simple 'Hello World' file.
The issue I'm having is that when the executable file is generated and I execute it (double-click), nothing happens. There is no console popping out and I can see no execution. I have read in the documentation that in MacOS and Windows there are explicit options in order to make this console appear or not, but not in Linux.
Any idea?
You should open your console, and use "python file.py" or "python3 file.py" command (it depends on Python version), where file.py is your file.
I hope that I helped.

How to run Python script on Ubuntu, Windows and MAC

I'm making Python software using wx GUI library but was wondering how to run this script on different OS's. For example, do I need to create executable installation file or bat file on Windows and sh file in Ubuntu?
I've got #!/usr/bin/env python at the top of the file and I can seem to run it by actually double clicking it and clicking it on "RUN" on prompt window but I would like it to be more professional as the users are not programmers.
Being used to run python scripts on both linux and Windows environments, I know that you can use the same script for both environments.
Keep using your shebang in Linux, it won't be procesed in windows (as it is actually a comment :).
Once Python is installed in Windows, you can actually simply double click on the script (it will run by default in a cmd window), run it using the cmd or launch it in idle.
If you want to develop python scripts on windows however, you'll need some more tools :).
If you want to be more professional (and prevent your users to modify the code :), you can still think about creating an exe file : http://www.lyxia.org/blog/developpement/python/creez-des-executables-46
(warning, french inside), by using pyinstaller http://www.pyinstaller.org/ . Works for windows and linux

How can I run a python script on windows?

Can anyone please tell me an IDE for running python programs? Is it possible to run the program through command line?
Take a look at ActiveState's ActivePython. It's quite a nice implementation of Python on Windows. Another way is using Cygwin's Python port. These two are Python implementations. I don't use an IDE, I write my Python code in Notepad++.
To run a python program after saving it to C:\Users\vaibhav\Code\myscript.py:
ActivePython: If I remember right, ActiveState updates the path correctly. So it should be a s simple as:
Press "start" in the task bar
In the search field search for "cmd"
In the appearing box navigate to your folder with the python script: dir Users\vaibhav\Code
call python myscript.py and you're done
Cygwin: After installing Cygwin, you have a full-featured bash terminal on your Windows machine.
click on the Cygwin icon on your desktop
In the appearing window navigate to the folder with your python script: cd /cygdrive/c/Users/vaibhav/Code
type python myscript.py
e voila
IDE for running scripts? You can have any IDE you like, but if you need only to run python scripts you go like this:
python.exe pythonScript.py
I like the EasyEclipse for python distribution. You'd need to have python and java installed of course.
PyDev and Komodo Edit are 2 nice Python IDE on Windows.
I also like the SciTE text editor very much.
These 3 solutions make possible to run Python scripts
I tried to run a Python script with multiprocessing on windows. see this tutorial
It does not work on Windows, but on raspian it went very well. Thus I knew that it was a Windows problem. I installed cygwin and followed this tutorial Installing Python inside Cygwin.
After that I additionally installed numpy with the command easy_install numpy and now i can run python scripts with multiprocessing on windows (from cygwin).

Categories