I have two Python3 interpreter files. One in /usr/bin/python3 and one in /opt/costume/python3, they should be automatically installed. I want to create a python script which can switch between this two python3 if one is not on the system. Is this even possible with a python script? Or should i switch to a bash script? Thanks
Asked
Active
Viewed 65 times
0
-
1What do you mean by switch? In what environment do you call Python? How do these tho get into your `$PATH` before being called? – LinFelix Oct 13 '22 at 10:49
-
The question you are asking is mostly opinion based but to the part whether it is possible, you should be able to create a launcher python script which tries to lauch your worker python script with `subprocess` module. With this module, you can try/catch error if the one python interpreter is not installed etc. However bash is a good approach too, if you dont want this mechanism to be os independant. – Bijay Regmi Oct 13 '22 at 10:49
-
First of all, thanks for the answer, i was thinking about a similar way. But i cant assume the installation of one interpreter. I could write it in bash but it would be better if could find a solution in python. – Gegnatz Oct 13 '22 at 14:06
-
Why does it matter where Python is installed exactly? Are you new to writing scripts on Linux? cause normally you would just use a shebang, [`#!/usr/bin/env python3`](/q/2429511/4518341) and let `env` handle it (selecting which one from the environment). – wjandrea Oct 13 '22 at 17:28
-
It matters because the script should be prefer the costume python3. These two python interpreter are not the same. I know about `#!/usr/bin/env python3` but `env` trys to select the `/usr/bin/python3` interpreter. And as i said, i cant assume the installation of one interpreter. – Gegnatz Oct 14 '22 at 07:09