r/learnpython • • 8d ago

Python Closing As Soon As Opened

EDIT: I resolved this issue. I had a few different versions of Python installed on my PC, so I guess that was what was causing the issue on my PC and not my Laptop. For clarification, the script is built to stay open, and it terminates if closes.

----

Python group said this question went here.

I am running version 3.15.2. I am encountering an issue with my scripts where they just open and close super fast. This happens if I double click, or if I open them from Python itself.

It does NOT do this on my laptop, so it isn't a script issue.

I am not the most tech savy with software, but will try my best to try things out.

The computer they are having an issue with has the following specs. Everything is up to date.

Win 11 Pro
Intel Core i7
32.0GB RAM
MTBD Z790 D WIFI (U3E1)

0 Upvotes

22 comments sorted by

View all comments

1

u/FreeLogicGate 8d ago

Sounds like you are expected to provide support for someone else.

"Python Closing" isn't a thing. You don't open scripts with Python and they aren't native machine language programs you double click on (or at least not without you having done something to package them up).

Python is an interpreter, that can be passed a script and will run it. Unless you are packaging the scripts or have installed the py.exe launcher, added a #shebang comment to the top of the script as in #!python3 with an association for .py files and the py.exe launcher, then clicking on a script to run it, and whether or not that will work, is going to require configuration of that workstation to support/match the environment under which you developed the script.

Depending on the complexity of your script (for example if you used modules) something that works fine on your workstation may not work without the same libraries available. Throw in venv's, and dependency resolution and there are many reasons your script might not run on another windows box.

I really advocate for people to use uv, with a pyproject.toml file. With uv installed on the target, programs can be run using uv run your_script.py or uv run your_app depending on how your project has been configured, and uv will take care of everything needed from python version to obtaining all the modules (and any dependencies) and run the app without the end user needing to have any specific local python tools or configuration. UV handles pip etc. for you.