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
Related
I have this file.py:
import os
os.system("pip install pip")
os.system("pip install selenium")
How do I make it work for MAC and what is te equivallent of a .bat file in MAC to execute the file.py.
Your file.py script will generally work fine on Mac as long as the environment the script is running in is set up right. Most notably, the pip executable has to be findable via the current PATH variable. You might benefit by looking at the subprocess module, which is an alternative API for running external commands. It is a more robust mechanism for doing so.
The equivalent of a .BAT file is a shell script. You have a choice as to which shell to use to run the script. I think the most common source is the Bash shell. It is often the case that you use whatever shell is running at your command prompt. This functionality is generally much more general and flexible than a .BAT file is on Window. See this link for a discussion of many of the issues:
https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/shell_scripts/shell_scripts.html
A shell script can just be one or more commands that you might run in your Terminal. For example, to run test.py at a Terminal prompt, you'd do this:
> python test.py
The simplest equivalent in a shell script would be the same thing:
python test.py
A script that looks like this is run by whatever shell executes the shell script. What is more usually done is that a "shebang" line is added to the top of the shell script to explicitly define which shell will be used to run the script. So what the single line script above should really look like is this:
#!/bin/sh
python test.py
This may be starting to make your head spin. I would suggest reviewing the link I gave above, and possibly reviewing some other materials that explain shell scripts. Note that nothing about shell scripts is unique to the Mac. The concept is exactly the same on Linux, Unix, etc.
BTW, do you really want pip install pip? What does that do? Doesn't the pip package have to already be installed if the pip command is working?
I've scrolled the internet all over and theres no simple, clean explanation for this. How can I open the Python shell, but inside a terminal window such as CMD? I have an application for it, but want to run it inside a terminal, so I can practice Python code inside my IDE like VS code.
If you have a reasonably new version of Python you need to run py.exe (or just py) instead of python.exe, because the real python executable (python.exe) is not in your path environment variable by default, whereas py.exe is in the /windows directory and thus automatically in path.
So to run your script type py yourscript.py from the directory of your script. If you just run py it will start the interactive interpreter.
Look e.g. at https://www.python-course.eu/python3_execute_script.php
Under the title Start a Python script (almost at the beginning)
there is an instruction. Just write from the command prompt:
python,
a space,
and the filename containing your script, with .py extension.
As in each command, press Enter and your script will be executed.
Of course, I assume that you have installed Python on your computer.
If this is not the case, start from installing it.
I have quite a new Python version installed (3.6.5) and start Python
writing just python. Writing just py also does the job, but (IMHO)
it is not necessary.
If you want to start Python interpreter and play around with some
Python commands, write just python and Enter. The interpreter will
start and display its own command prompt (>>>).
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.
I want to paste my code from my text editor into the IDLE window, but when I do the program won't run. Is there a way to run my program without copying and pasting into the IDLE window. (I'm a complete NOOB)
To run a Python 3 program in IDLE, from the command line:
$ python3 -m idlelib -r your_script.py
For earlier Python versions, see How to start IDLE (Python editor) without using the shortcut on Windows Vista?
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).