Friday, May 3, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 346  / 1 Year ago, thu, january 26, 2023, 1:14:16

After very few issues only I moved my application from Python2 to Python3 making sure it will still run with Python 2.7, and hence has python >= 2.7 as dependency only.



This was mainly done because Python3, and some dependencies are not installed in a default 12.04 LTS, and I do not want my users to have to install all Python3 only to run my script.



When I create an appname.desktop launcher I now need to decide if it starts my application using Python2, or Python3 like



EXEC=python /path/app.py
EXEC=python3 /path/app.py


But what I would like it to do is to




  1. Launch the application with the Python3 interpreter if Python3 is installed.

  2. Otherwise use Python2 if Python3 is not installed.



How can this be done? Do I need to tell it in my package installation script, or can I have a launcher which can handle both (in case people install Python3 after they had installed my script)?


More From » launcher

 Answers
7

It sounds too obvious to a good answer but...



Why you don't use a bash script as your app binary. I mean drop in /usr/bin/ a bash script that checks for python3 and then runs the real script.



The launcher will just point to the bash script.



It will even work from the command line (as only the bash script will be on PATH).


[#33953] Friday, January 27, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
itutejagua

Total Points: 89
Total Questions: 124
Total Answers: 113

Location: British Indian Ocean Territory
Member since Sun, Feb 13, 2022
2 Years ago
;