[QGIS-Developer] discover python executable in use
andreasplesch at gmail.com
Tue Jun 6 15:18:57 PDT 2017
I think I am starting to understand bit better what is happening. Since
qgis (probably) completely embeds the python interpreter, eg. links to
libpython, the value of sys.executable does not really map to this
situation. Apparently, the interpretation differs depending on the platform.
So if I want to start a detached python process, it is not unreasonable to
have to look around for the python executable although it would be great if
there is some worked out cross-platform approach.
A pseudo-code strategy (for 2.18) could be:
on linux, use sys.executable but if sys.version is 3, warn and guess
dir(sys.executable)/python2 (check that the file exists). Actually, it
should be fine to just always use dir(sys.executable)/python2 .
on windows (sys.platform.startswith('win')), use
This appears to work well enough but I suspect there are better approaches ?
Sort of similarly, killing a detached QProcess seems to require platform
specific code as well. os.kill works for linux but windows seems to require
its own system executed 'taskkill /pid'.
If this all seems to be completely off, any suggestions or ideas are
On Mon, Jun 5, 2017 at 9:49 AM, Andreas Plesch <andreasplesch at gmail.com>
> Using the Python console on 2.18
> import sys
> 1) on Windows (2.18.9 32bit):
> which unexpectedly does not appear to be a Python interpreter
> 2) on Linux (2.18.3. 64bit)
> which does appear to be the Python interpreter in use by the console.
> Is there a cross platform way to discover the Python interpreter in
> current use ? Would 1) considered to be a possible bug somewhere ?
> I want to use it for
> QProcess.startDetached(sys.executable, args, root_folder)
> Andreas Plesch
> 39 Barbara Rd.
> Waltham, MA 02453
39 Barbara Rd.
Waltham, MA 02453
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the QGIS-Developer