Repository: pypa/virtualenv

Issue:
conda commands as Python3 subprocesses inside a virtualenv fail under macOS
**Issue**

Describe what's the expected behaviour and what you're observing.

Running any conda command as a Python3 subprocess inside of a virtualenv fails under macOS with `ModuleNotFoundError: No module named 'conda'`. This works fine under Linux or when using Python2 or virtualenv <20.
The same works fine also before activating and after deactivating the virtualenv.

Tested on the latest virtualenv 20.0.9.

See https://travis-ci.org/nsoranzo/bioblend/builds/660456892 for how to reproduce on TravisCI and example of success and failure of the same commands under Linux and macOS respectively.

**Environment**

Provide at least:
- OS: macOS
- ``pip list`` of the host python where ``virtualenv`` is installed:

  ```console
  Package    Version
  ---------- -------
  GDAL       2.4.2  
  mercurial  5.2    
  numpy      1.17.4 
  pip        19.3.1 
  protobuf   3.11.1 
  setuptools 41.6.0 
  six        1.13.0 
  wheel      0.33.6 
  ```

**Output of the virtual environment creation**

Make sure to run the creation with `-vvv --with-traceback`:

```console
152 setup logging to NOTSET [DEBUG report:43]
152 created app data folder /Users/travis/Library/Application Support/virtualenv [DEBUG app_data:52]
165 find interpreter for spec PythonSpec(implementation=CPython, major=3) [INFO builtin:44]
166 proposed PythonInfo(spec=CPython3.7.5.final.0-64, exe=/usr/local/opt/python/bin/python3.7, platform=darwin, version='3.7.5 (default, Nov  1 2019, 02:16:38) \n[Clang 10.0.0 (clang-1000.11.45.5)]', encoding_fs_io=utf-8-UTF-8) [INFO builtin:50]
166 accepted PythonInfo(spec=CPython3.7.5.final.0-64, exe=/usr/local/opt/python/bin/python3.7, platform=darwin, version='3.7.5 (default, Nov  1 2019, 02:16:38) \n[Clang 10.0.0 (clang-1000.11.45.5)]', encoding_fs_io=utf-8-UTF-8) [DEBUG builtin:52]
173 filesystem is not case-sensitive [DEBUG info:28]
278 create virtual environment via CPython3Posix(dest=/Users/travis/build/nsoranzo/bioblend/.venv, clear=False, global=False) [INFO session:52]
278 create folder /Users/travis/build/nsoranzo/bioblend/.venv/bin [DEBUG _sync:21]
278 create folder /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages [DEBUG _sync:21]
279 write /Users/travis/build/nsoranzo/bioblend/.venv/pyvenv.cfg [DEBUG pyenv_cfg:34]
279 	home = /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7 [DEBUG pyenv_cfg:38]
279 	implementation = CPython [DEBUG pyenv_cfg:38]
279 	version_info = 3.7.5.final.0 [DEBUG pyenv_cfg:38]
279 	virtualenv = 20.0.9 [DEBUG pyenv_cfg:38]
280 	include-system-site-packages = false [DEBUG pyenv_cfg:38]
280 	base-prefix = /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7 [DEBUG pyenv_cfg:38]
280 	base-exec-prefix = /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7 [DEBUG pyenv_cfg:38]
280 	base-executable = /usr/local/opt/python/bin/python3.7 [DEBUG pyenv_cfg:38]
280 symlink /usr/local/opt/python/bin/python3.7 to /Users/travis/build/nsoranzo/bioblend/.venv/bin/python [DEBUG _sync:40]
282 create /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/_virtualenv.py [DEBUG api:60]
283 create virtualenv import hook file /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/_virtualenv.pth [DEBUG api:63]
283 ============================== target debug ============================== [DEBUG session:54]
284 debug via /Users/travis/build/nsoranzo/bioblend/.venv/bin/python /usr/local/lib/python3.7/site-packages/virtualenv/create/debug.py [DEBUG creator:182]
283 {
  "sys": {
    "executable": "/Users/travis/build/nsoranzo/bioblend/.venv/bin/python",
    "_base_executable": "/Users/travis/build/nsoranzo/bioblend/.venv/bin/python",
    "prefix": "/Users/travis/build/nsoranzo/bioblend/.venv",
    "base_prefix": "/usr/local/opt/python/bin/../Frameworks/Python.framework/Versions/3.7",
    "real_prefix": null,
    "exec_prefix": "/Users/travis/build/nsoranzo/bioblend/.venv",
    "base_exec_prefix": "/usr/local/opt/python/bin/../Frameworks/Python.framework/Versions/3.7",
    "path": [
      "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python37.zip",
      "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7",
      "/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload",
      "/Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages"
    ],
    "meta_path": [
      "<class '_virtualenv._Finder'>",
      "<class '_frozen_importlib.BuiltinImporter'>",
      "<class '_frozen_importlib.FrozenImporter'>",
      "<class '_frozen_importlib_external.PathFinder'>"
    ],
    "fs_encoding": "utf-8",
    "io_encoding": "UTF-8"
  },
  "version": "3.7.5 (default, Nov  1 2019, 02:16:38) \n[Clang 10.0.0 (clang-1000.11.45.5)]",
  "os": "<module 'os' from '/usr/local/opt/python/bin/../Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py'>",
  "site": "<module 'site' from '/usr/local/opt/python/bin/../Frameworks/Python.framework/Versions/3.7/lib/python3.7/site.py'>",
  "datetime": "<module 'datetime' from '/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/datetime.py'>",
  "math": "<module 'math' from '/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload/math.cpython-37m-darwin.so'>",
  "json": "<module 'json' from '/usr/local/opt/python/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py'>"
} [DEBUG session:55]
354 add seed packages via FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/Users/travis/Library/Application Support/virtualenv/seed-app-data/v1) [INFO session:59]
355 Attempting to acquire lock 4344232784 on /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels.lock [DEBUG filelock:270]
356 Lock 4344232784 acquired on /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels.lock [INFO filelock:274]
357 get bundled wheel /usr/local/lib/python3.7/site-packages/virtualenv/seed/embed/wheels/pip-20.0.2-py2.py3-none-any.whl [DEBUG acquire:51]
357 get bundled wheel /usr/local/lib/python3.7/site-packages/virtualenv/seed/embed/wheels/setuptools-45.3.0-py3-none-any.whl [DEBUG acquire:51]
358 get bundled wheel /usr/local/lib/python3.7/site-packages/virtualenv/seed/embed/wheels/wheel-0.34.2-py2.py3-none-any.whl [DEBUG acquire:51]
373 install wheel from wheel /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels/wheel-0.34.2-py2.py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:46]
373 build install image to /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/wheel-0.34.2-py2.py3-none-any of wheel-0.34.2-py2.py3-none-any.whl [DEBUG base:57]
374 install setuptools from wheel /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels/setuptools-45.3.0-py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:46]
375 build install image to /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/setuptools-45.3.0-py3-none-any of setuptools-45.3.0-py3-none-any.whl [DEBUG base:57]
375 install pip from wheel /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels/pip-20.0.2-py2.py3-none-any.whl via CopyPipInstall [DEBUG via_app_data:46]
376 build install image to /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/pip-20.0.2-py2.py3-none-any of pip-20.0.2-py2.py3-none-any.whl [DEBUG base:57]
418 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmp4niwmfd9/wheel-3.7 to 755 [INFO util:566]
419 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmp4niwmfd9/wheel to 755 [INFO util:566]
421 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmp4niwmfd9/wheel3 to 755 [INFO util:566]
432 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/wheel-0.34.2-py2.py3-none-any/wheel to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/wheel [DEBUG _sync:48]
466 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/wheel-0.34.2-py2.py3-none-any/wheel-0.34.2.dist-info to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/wheel-0.34.2.dist-info [DEBUG _sync:48]
474 copy /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/wheel-0.34.2-py2.py3-none-any/wheel-0.34.2.virtualenv to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/wheel-0.34.2.virtualenv [DEBUG _sync:48]
475 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/wheel-3.7 to 755 [INFO util:566]
475 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/wheel to 755 [INFO util:566]
476 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/wheel3 to 755 [INFO util:566]
476 generated console scripts wheel3 wheel-3.7 wheel [DEBUG base:53]
542 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmpdfedv6sv/easy_install to 755 [INFO util:566]
543 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmpdfedv6sv/easy_install3 to 755 [INFO util:566]
544 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmpdfedv6sv/easy_install-3.7 to 755 [INFO util:566]
563 copy /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/setuptools-45.3.0-py3-none-any/easy_install.py to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/easy_install.py [DEBUG _sync:48]
564 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/setuptools-45.3.0-py3-none-any/pkg_resources to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/pkg_resources [DEBUG _sync:48]
584 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/setuptools-45.3.0-py3-none-any/setuptools to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/setuptools [DEBUG _sync:48]
655 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/setuptools-45.3.0-py3-none-any/setuptools-45.3.0.dist-info to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/setuptools-45.3.0.dist-info [DEBUG _sync:48]
667 copy /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/setuptools-45.3.0-py3-none-any/setuptools-45.3.0.virtualenv to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/setuptools-45.3.0.virtualenv [DEBUG _sync:48]
668 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/easy_install to 755 [INFO util:566]
669 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/easy_install3 to 755 [INFO util:566]
670 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/easy_install-3.7 to 755 [INFO util:566]
671 generated console scripts easy_install3 easy_install-3.7 easy_install [DEBUG base:53]
746 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmp9zqbno9l/pip to 755 [INFO util:566]
746 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmp9zqbno9l/pip3 to 755 [INFO util:566]
747 changing mode of /var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/tmp9zqbno9l/pip-3.7 to 755 [INFO util:566]
781 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/pip-20.0.2-py2.py3-none-any/pip to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/pip [DEBUG _sync:48]
969 copy directory /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/pip-20.0.2-py2.py3-none-any/pip-20.0.2.dist-info to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/pip-20.0.2.dist-info [DEBUG _sync:48]
972 copy /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/image/CopyPipInstall/pip-20.0.2-py2.py3-none-any/pip-20.0.2.virtualenv to /Users/travis/build/nsoranzo/bioblend/.venv/lib/python3.7/site-packages/pip-20.0.2.virtualenv [DEBUG _sync:48]
973 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/pip to 755 [INFO util:566]
974 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/pip3 to 755 [INFO util:566]
975 changing mode of /Users/travis/build/nsoranzo/bioblend/.venv/bin/pip-3.7 to 755 [INFO util:566]
975 generated console scripts pip3 pip pip-3.7 [DEBUG base:53]
975 Attempting to release lock 4344232784 on /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels.lock [DEBUG filelock:315]
975 Lock 4344232784 released on /Users/travis/Library/Application Support/virtualenv/seed-app-data/v1/3.7/wheels.lock [INFO filelock:318]
976 add activators for Bash, CShell, Fish, PowerShell, Python, Xonsh [INFO session:65]
980 write /Users/travis/build/nsoranzo/bioblend/.venv/pyvenv.cfg [DEBUG pyenv_cfg:34]
980 	home = /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7 [DEBUG pyenv_cfg:38]
980 	implementation = CPython [DEBUG pyenv_cfg:38]
981 	version_info = 3.7.5.final.0 [DEBUG pyenv_cfg:38]
981 	virtualenv = 20.0.9 [DEBUG pyenv_cfg:38]
981 	include-system-site-packages = false [DEBUG pyenv_cfg:38]
981 	base-prefix = /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7 [DEBUG pyenv_cfg:38]
981 	base-exec-prefix = /usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7 [DEBUG pyenv_cfg:38]
982 	base-executable = /usr/local/opt/python/bin/python3.7 [DEBUG pyenv_cfg:38]
982 created virtual environment CPython3.7.5.final.0-64 in 833ms
  creator CPython3Posix(dest=/Users/travis/build/nsoranzo/bioblend/.venv, clear=False, global=False)
  seeder FromAppData(download=False, pip=latest, setuptools=latest, wheel=latest, via=copy, app_data_dir=/Users/travis/Library/Application Support/virtualenv/seed-app-data/v1)
  activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator [WARNING __main__:21]
```



Discussion:
@nsoranzo does the same happen within a venv, or only virtualenv is affected by this?
@gaborbernat It seems that venv is affected on macOS but not on Linux, as virtualenv: https://travis-ci.org/nsoranzo/bioblend/builds/660579284
@nsoranzo, in this case, this becomes either a conda or CPython venv module upstream bug, did you open tickets there?

A side effect of virtualenv moving to the venv style virtual environments is that users now tend to discover all the venv bugs here 🤷‍♂ 
Thanks for the fast response! No, I did not open an upstream issue yet, I didn't know it was a venv bug till now! (I don't think it's conda's, given it works fine on Linux and with old virtualenv).

I have feeling the issue could get more attention if you open it, but happy to do it myself if you prefer (Should this go on https://bugs.python.org/ ?).
Unless I'm missing something, the issue seems to be that the conda command expects to be able to import conda in the active Python, but conda (the library) isn't installed in the active venv, so it can't.

The fix is likely to be for the conda script to use a specific Python binary, not just pick up whatever is first on `PATH`.

Edit: My mistake, the conda script has a shebang:

```python
#!/Users/travis/miniconda3/bin/python
# -*- coding: utf-8 -*-
import sys
# Before any more imports, leave cwd out of sys.path for internal 'conda shell.*' commands.
# see https://github.com/conda/conda/issues/6549
if len(sys.argv) > 1 and sys.argv[1].startswith('shell.') and sys.path and sys.path[0] == '':
    # The standard first entry in sys.path is an empty string,
    # and os.path.abspath('') expands to os.getcwd().
    del sys.path[0]
if __name__ == '__main__':
    from conda.cli import main
    sys.exit(main())
```

So it should be getting run by the right interpreter. Sorry for the noise 🙁 
Yeah needs to go on bugs.python.org; have a feeling this could be related to https://github.com/python/cpython/pull/9516 🤷‍♂ 
@pfmoore Yep, I was going to point out that I checked that in https://travis-ci.org/nsoranzo/bioblend/jobs/660579286#L182 (and the conda lib is indeed installed in `/Users/travis/miniconda3/lib`).
Note it could be a conda bug too, hence why saying that could be worthwhile open a bug first there.
I'll close the issue for now. Please post here the upstream bug report links, so if other people run into it they can be redirected. If anything actionable comes out of those I'll reopen and make the changes.
> Yeah needs to go on bugs.python.org; have a feeling this could be related to https://github.com/python/cpython/pull/9516

@gaborbernat I can confirm this is indeed due to https://github.com/python/cpython/pull/9516 , see https://travis-ci.org/github/nsoranzo/bioblend/jobs/665637175 where deleting `os.environ['__PYVENV_LAUNCHER__']` before launching the conda subprocess fixes the issue.

Now that https://github.com/python/cpython/pull/9516 has been merged, would you consider patching virtualenv to remove `__PYVENV_LAUNCHER__` for Python3 environments on macOS, given it will take a while for the upstream PYthon fix to reach existing installations?
We could patch it via the ``pth`` file. What would this imply ``python3.7.(<7)``, ``python3.8.(<3)`` on macOs?
> We could patch it via the `pth` file. What would this imply `python3.7.(<7)`, `python3.8.(<3)` on macOs?

I think: <=3.7.7 or (>=3.8 and <=3.8.2)
Or just <3.9 if you want to keep it simple, a guarded `del` like `if '__PYVENV_LAUNCHER__' in os.environ: del os.environ['__PYVENV_LAUNCHER__']` shouldn't create issues on future 3.7 and 3.8 point releases.
I prefer to have the customization only active when needed, instead of always on and guarded. Let's not have redundant generated code.
Sure!

Resolving patch:
diff --git a/src/virtualenv/create/via_global_ref/api.py b/src/virtualenv/create/via_global_ref/api.py
--- a/src/virtualenv/create/via_global_ref/api.py
+++ b/src/virtualenv/create/via_global_ref/api.py
@@ -67,19 +67,23 @@ def add_parser_arguments(cls, parser, interpreter, meta, app_data):
             )
 
     def create(self):
-        self.patch_distutils_via_pth()
+        self.install_patch()
 
-    def patch_distutils_via_pth(self):
+    def install_patch(self):
+        text = self.env_patch_text()
+        if text:
+            pth = self.purelib / "_virtualenv.pth"
+            logging.debug("create virtualenv import hook file %s", pth)
+            pth.write_text("import _virtualenv")
+            dest_path = self.purelib / "_virtualenv.py"
+            logging.debug("create %s", dest_path)
+            dest_path.write_text(text)
+
+    def env_patch_text(self):
         """Patch the distutils package to not be derailed by its configuration files"""
         with ensure_file_on_disk(Path(__file__).parent / "_virtualenv.py", self.app_data) as resolved_path:
             text = resolved_path.read_text()
-            text = text.replace('"__SCRIPT_DIR__"', repr(os.path.relpath(str(self.script_dir), str(self.purelib))))
-        dest_path = self.purelib / "_virtualenv.py"
-        logging.debug("create %s", dest_path)
-        dest_path.write_text(text)
-        pth = self.purelib / "_virtualenv.pth"
-        logging.debug("create virtualenv import hook file %s", pth)
-        pth.write_text("import _virtualenv")
+            return text.replace('"__SCRIPT_DIR__"', repr(os.path.relpath(str(self.script_dir), str(self.purelib))))
 
     def _args(self):
         return super(ViaGlobalRefApi, self)._args() + [("global", self.enable_system_site_package)]
diff --git a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py
--- a/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py
+++ b/src/virtualenv/create/via_global_ref/builtin/cpython/cpython3.py
@@ -1,6 +1,7 @@
 from __future__ import absolute_import, unicode_literals
 
 import abc
+from textwrap import dedent
 
 from six import add_metaclass
 
@@ -22,6 +23,24 @@ class CPython3Posix(CPythonPosix, CPython3):
     def can_describe(cls, interpreter):
         return is_mac_os_framework(interpreter) is False and super(CPython3Posix, cls).can_describe(interpreter)
 
+    def env_patch_text(self):
+        text = super(CPython3Posix, self).env_patch_text()
+        if self.pyvenv_launch_patch_active(self.interpreter):
+            text += dedent(
+                """
+                # for https://github.com/python/cpython/pull/9516, see https://github.com/pypa/virtualenv/issues/1704
+                import os
+                if "__PYVENV_LAUNCHER__" in os.environ:
+                    del os.environ["__PYVENV_LAUNCHER__"]
+                """
+            )
+        return text
+
+    @classmethod
+    def pyvenv_launch_patch_active(cls, interpreter):
+        ver = interpreter.version_info
+        return interpreter.platform == "darwin" and ((3, 7, 8) > ver >= (3, 7) or (3, 8, 3) > ver >= (3, 8))
+
 
 class CPython3Windows(CPythonWindows, CPython3):
     """"""


Test patch:
diff --git a/tests/unit/create/test_creator.py b/tests/unit/create/test_creator.py
--- a/tests/unit/create/test_creator.py
+++ b/tests/unit/create/test_creator.py
@@ -20,6 +20,7 @@
 
 from virtualenv.__main__ import run, run_with_catch
 from virtualenv.create.creator import DEBUG_SCRIPT, Creator, get_env_debug_info
+from virtualenv.create.via_global_ref.builtin.cpython.cpython3 import CPython3Posix
 from virtualenv.create.via_global_ref.builtin.python2.python2 import Python2
 from virtualenv.discovery.builtin import get_interpreter
 from virtualenv.discovery.py_info import PythonInfo
@@ -219,6 +220,13 @@ def list_to_str(iterable):
         assert python_w.exists()
         assert python_w.read_bytes() != result.creator.exe.read_bytes()
 
+    if CPython3Posix.pyvenv_launch_patch_active(PythonInfo.from_exe(python)) and creator_key != "venv":
+        result = subprocess.check_output(
+            [str(result.creator.exe), "-c", 'import os; print(os.environ.get("__PYVENV_LAUNCHER__"))'],
+            universal_newlines=True,
+        ).strip()
+        assert result == "None"
+
 
 @pytest.mark.skipif(not CURRENT.has_venv, reason="requires interpreter with venv")
 def test_venv_fails_not_inline(tmp_path, capsys, mocker):