[New-bugs-announce] [issue42041] venv subprocess call to python resolves to wrong interpreter

Mark Keller report at bugs.python.org
Thu Oct 15 01:50:57 EDT 2020


New submission from Mark Keller <markooo.keller at gmail.com>:

Hey,

Wanted to report this weird behavior I saw recently. Let me first explain how to reproduce and then talk about where I think the issue comes from.

I attached a tar.gz file with 2 Python files in it.

Here's how to reproduce:
0. Make sure that pytest is unavailable in your command line, or please edit to another library that you don't have available from another Python install (make sure to update the import statement in `script1.py`).
1. Untar the 2 scripts into current working directory. Note: I reproduced on a Windows VM (Version 10.0.18363 Build 18363).
2. Make a Python 3.7, or 3.8 environment venv. Note: I used Python 3.8.2.
3. Activate venv and install pytest in it.
4. Run `python run_scripts.py` and observe the error.

Note: The same thing works on Python 3.6 as expected.

My team observed this issue when virtualenv released this Monday. It changed how it works with Windows and Python 3.7+, before it was not using the Windows redirect script generated by venv and just worked like how older versions on Windows do.
But what we are seeing is that if you start a subprocess call to `python` then that gets resolved to the system wide Python binary without the venv site-packages being in PYTHONPATH.
So the subprocess will fail when importing pytest in the subprocess.

If this is not clear please don't hesitate to ask me for clarification, or refer to https://github.com/pypa/virtualenv/issues/1981 for more debugging info.

Another interesting thing that I noticed is that if you make a subprocess call to `pytest` instead then that gets resolved correctly.

----------
components: Windows
files: repro.tar.gz
messages: 378665
nosy: keller00, paul.moore, steve.dower, tim.golden, vinay.sajip, zach.ware
priority: normal
severity: normal
status: open
title: venv subprocess call to python resolves to wrong interpreter
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file49520/repro.tar.gz

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


More information about the New-bugs-announce mailing list