This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sys.executable different in os.execv'd python3.6 virtualenv session in python2 vs python3
Type: Stage: resolved
Components: macOS Versions: Python 3.6, Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Stephen Moore, barry, cheryl.sabella, ned.deily, r.david.murray, ronaldoussoren, vinay.sajip
Priority: normal Keywords:

Created on 2017-10-02 03:12 by Stephen Moore, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (6)
msg303507 - (view) Author: Stephen Moore (Stephen Moore) Date: 2017-10-02 03:12
Hi,

I've come across a problem whereby if you do an os.execv to a python3.6 virtualenv python inside python2.7 vs python3.6 then the resulting python session has a different sys.executable.

Where if you os.execv from python2.7 the sys.executable is equal to the virtualenv python

Whereas from python3.6 the resulting python session has a sys.executable of the system python.

An example of this in play can be found at https://gist.github.com/delfick/d750dc83e3b28e90cef8e2bfbd5b175a

Note that I don't see the problem if the virtualenv is based on python2.7 (https://gist.github.com/delfick/f1ad6872e2614189a7d98f2583ffc564)
msg303530 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-10-02 11:35
virtualenv is not part of the standard library.  What happens if you use venv instead?
msg303551 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2017-10-02 16:59
I suspect what is being seen here is essentially a duplicate of Issue31363. On macOS framework builds, a python launcher executable is used (Mac/Tools/pythonw.c) to exec the real Python interpreter binary and the launcher uses the __PYVENV_LAUNCHER__ environment variable to be able to handle symlinks (work initially implemented in Issue15307).
msg303569 - (view) Author: Stephen Moore (Stephen Moore) Date: 2017-10-02 23:15
It appears the problem doesn't appear when using python3 -m venv.

Also it seems __PYVENV_LAUNCHER__ is set to the virtualenv's python except when it's a python3.6 virtualenv and we os.execv from python3.6, where it's set the system python.

Should I be making an issue with the virtualenv project?
msg303570 - (view) Author: Stephen Moore (Stephen Moore) Date: 2017-10-02 23:23
I just realised python3 sets it's own __PYVENV_LAUNCHER__ and if you unset it before calling to os.execv, then the virtualenv has the correct sys.executable.
msg327018 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-10-03 23:57
The original OP said this wasn't an issue with venv, so closing as not a bug.
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75841
2018-10-03 23:57:30cheryl.sabellasetstatus: open -> closed

nosy: + cheryl.sabella
messages: + msg327018

resolution: not a bug
stage: resolved
2017-10-02 23:23:56Stephen Mooresetmessages: + msg303570
2017-10-02 23:15:40Stephen Mooresetmessages: + msg303569
2017-10-02 16:59:17ned.deilysetnosy: + vinay.sajip
messages: + msg303551
2017-10-02 13:39:49barrysetnosy: + barry
2017-10-02 11:35:04r.david.murraysetnosy: + r.david.murray
messages: + msg303530
2017-10-02 03:12:27Stephen Moorecreate