I have researched this question and found Running subprocess within different virtualenv with python, but my situation is a little different.
I have an astrophotography application which I run on Ubuntu Linux 24.04.2 LTS. This application has a facility for launching python scripts. It does so using its own venv. They supply a python script to launch a third party executable that sharpens an image that the main application is working with. This third party executable optionally can use GPU acceleration given the presence of a suitable GPU on the system running the script. This GPU detection functionality depends on code in the main application's venv.
Another possibly important detail is that the third-party executable is itself compiled from a python script, which presumably uses a venv. It is not c++ or other similar language.
The situation is when the script is run from the application, an error message is emitted saying that GPU acceleration is not available, and the process drops back to CPU processing which takes perhaps perhaps 100 times as long. This error message is incorrect.
I know this because the third party executable can be successfully run standalone when the much faster GPU processing can be observed.
To do that one must manually copy the file to be processed to a specific directory where the standalone executable expects to find it. If running from the application, the existing python script automatically copies the selected file to the executable's input directory, while also copying the processed file back from the executable's output directory to the same directory where the original image was located, a very convenient feature.
The problem lies with the application's python venv, which incorrectly detects whether or not the GPU support is available. Apparently, this is one big thorny mess which the application's developers are working on. When run standalone, the executable uses the system's python venv (remember it is compiled python).
In the meantime I would like to develop a script that can be run from the application that handles all the file copying before and after launching another python script using the system venv which launches the executable. In other words, to avoid the problematic GPU detection logic, since I know that in my case the GPU is suitable.
Is this possible and if so, what would be the best way to do it?