I've trying to make an installer for my Linux Python program. As part of the installer, it checks for dependencies and python version. However, the Installer is obfuscated with pyarmor, and packed into a "onefile" binary using pyinstaller. As a result, the Python interpreter the installer is built with is also bundled with the app. So, when the program checks to see what version of Python is installed, it keeps returning the bundled interpreter's version, not the one installed on the user's computer. Is there anyway to run python code outside of the virtual environment to get the Python version installed on the user's computer?
I've tried various things such as generating a python file with the code that checks for the python version, and then placing a shebang at the top that points to the python binary installed on the user's computer but it always come back as permission denied. I even tried running the chmod command to give the python file executable permission, but I'm guessing my program can't make permission changes without the user doing it.
I'd really appreciate any tips or pointers. Thank you so much!
Yes, there is a way to run Python code outside of the virtual environment and get the Python version installed on the user's computer. You can achieve this by using the
subprocessmodule to execute a separate Python interpreter that is installed on the user's system. Here's how you can do it:get_python_version.py, which will print the Python version.subprocessto execute theget_python_version.pyscript with the system's Python interpreter and capture the output.get_python_version.pyscript from the package. This way, the script will be executed using the user's installed Python interpreter instead of the bundled one.With this approach, your installer will be able to accurately determine the Python version installed on the user's system by running code outside the virtual environment and the bundled interpreter.