You're effectively asking how to compile a Python script into an executable. That's not really how Python works, but you can still achieve what you want: an application that installs and runs without requiring the user to know how to start a script from the command line (or install Python for that matter).
Applications like pyinstaller allow you to package your script with just the files it needs for the OS you want to deliver to. https://www.pyinstaller.org
Install pyinstaller into your virtual environment:
pip install pyinstaller
Then test your script and run pyinstaller for it:
python my_script.py
pyinstaller my_script.py
That will create a folder called build
with everything needed to build your distributable, and one called dist
that has the result including a my_script.exe
. A user of your script would need everything in the folder, but nothing else.
If you prefer it to be a single executable, you can run this:
pyinstaller --onefile my_script
This, on Windows, would create a single my_script.exe
, but you need to realise that this is just an executable archive that will create a temporary folder somewhere, still containing the same as the dist
folder. More about that here: https://pyinstaller.readthedocs.io/en/v3.3.1/operating-mode.html
You can create a nice and simple installer using a tool like InnoSetup, which you can get here http://www.jrsoftware.org/isinfo.php. With it (or another installer builder like it), you can make an installer that puts your packaged script in a folder in Program Files
, allow a user to start it from the Start Menu (like an application like Word) and uninstall it when they no longer need it.