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
dir(sys.executable)/python-qgis.bat

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
gratefully received,

Andreas

On Mon, Jun 5, 2017 at 9:49 AM, Andreas Plesch <andreasple...@gmail.com>
wrote:

> Using the Python console on 2.18
>
> import sys
> sys.executable
>
> returns
>
> 1) on Windows (2.18.9 32bit):
>
> 'C:\\PROGRA~1\\QGIS2~1.18\\bin\\qgis-bin.exe'
>
> which unexpectedly does not appear to be a Python interpreter
>
> and
>
> 2) on Linux (2.18.3. 64bit)
>
> '/usr/bin/python'
>
> 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)
>
> Thanks,
>
> -Andreas
>
>
> --
> Andreas Plesch
> 39 Barbara Rd.
> Waltham, MA 02453
>



-- 
Andreas Plesch
39 Barbara Rd.
Waltham, MA 02453
_______________________________________________
QGIS-Developer mailing list
QGIS-Developer@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to