In powershell, when I run a python program with:
> python hello.py
The program runs and prints any output directly in the powershell window I'm working in. But when I try to do it without explicitly invoking python:
> hello.py
it opens up a separate window. How can I fix that so it behaves the same way it does when I invoke python explicitly?
To execute a file in IDLE, simply press the F5 key on your keyboard. You can also select Run → Run Module from the menu bar. Either option will restart the Python interpreter and then run the code that you've written with a fresh interpreter.
To run Python scripts with the python command, you need to open a command-line and type in the word python , or python3 if you have both versions, followed by the path to your script, just like this: $ python3 hello.py Hello World! If everything works okay, after you press Enter , you'll see the phrase Hello World!
Running a ScriptOpen the terminal by searching for it in the dashboard or pressing Ctrl + Alt + T . Navigate the terminal to the directory where the script is located using the cd command. Type python SCRIPTNAME.py in the terminal to execute the script.
If you add .PY
to the PATHEXT
environment variable, you should be able to run .\hello.py
or just .\hello
in the current console. Otherwise it will ShellExecute
the associated Python.File
command (check ftype Python.File
), which launches a new console. I checked this by temporarily modifying the environment variable:
$env:pathext = $env:pathext + ";.PY"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With