Trying to create a batch script for windows that runs a program with python3 if available else python2.
I know the script can be executed with $py -2 script.py
and py3 with $py -3 script.py.
and if I run py -0, it returns all the python versions.
How do I build this script?
I do not want to check if the python directory is available or not, I'd prefer to check in a way that is python location agnostic.
Not a full solution, but a method to detect which version of Python is installed:
You can check if Python 3 is installed by running py -3 --version and then checking the %ERRORLEVEL% variable in the batch script. If it is 0, then py -3 --version was successful, i.e. Python 3 is installed on the system. If it is nonzero, then Python 3 is not installed.
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