[issue42041] venv subprocess call to python resolves to wrong interpreter

Steve Dower report at bugs.python.org
Mon Oct 19 15:16:59 EDT 2020


Steve Dower <steve.dower at python.org> added the comment:

Proposed alternative based on Eryk's:

      For maximum reliability, use a fully-qualified path for the executable.
      To search for an unqualified name on :envvar:`PATH`, use
      :meth:`shutil.which`. On all platforms, passing :data:`sys.executable`
      is the recommended way to launch the current Python interpreter again,
      and use the ``-m`` command-line format to launch an installed module.

      Resolving the path of *executable* (or the first item of *args*) is
      platform dependent. For POSIX, see :meth:`os.execvpe`, and note that
      when resolving or searching for the executable path, *cwd* overrides the
      current working directory and *env* can override the ``PATH``
      environment variable. For Windows, see the documentation of the
      ``lpApplicationName`` and ``lpCommandLine`` parameters of WinAPI
      ``CreateProcess``, and note that when resolving or searching for the
      executable path with ``shell=False``, *cwd* does not override the
      current working directory and *env* cannot override the ``PATH``
      environment variable. Using a full path avoids all of these variations.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42041>
_______________________________________


More information about the Python-bugs-list mailing list