The virtualenv.pyz zipapp cannot be run with an arbitrary python.
See original GitHub issueIssue
The virtualenv.pyz zipapp cannot be run with an arbitrary python if that python already has an incompatible version of virtualenv installed. This makes scripting virtualenv hard.
Environment
- OS: Linux
pip list
of the host python wherevirtualenv
is installed: N/A - see Reproduction steps below.
Reproduction Steps
- All good baseline:
$ docker run --rm -it ubuntu:20.04
root@789c91e7e2d3:/# apt update &>/dev/null && apt install -y curl python3 python3-distutils &>/dev/null
root@789c91e7e2d3:/# curl -sSL -O https://raw.githubusercontent.com/pypa/get-virtualenv/20.4.7/public/virtualenv.pyz
root@789c91e7e2d3:/# python3 virtualenv.pyz a.venv
created virtual environment CPython3.8.5.final.0-64 in 274ms
creator CPython3Posix(dest=/a.venv, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/root/.local/share/virtualenv)
added seed packages: pip==21.1.2, setuptools==57.0.0, wheel==0.36.2
activators BashActivator,CShellActivator,FishActivator,PowerShellActivator,PythonActivator,XonshActivator
- Blow things up by installing virtualenv:
root@789c91e7e2d3:/# apt install -y python3-virtualenv &>/dev/null
root@789c91e7e2d3:/# python3 virtualenv.pyz b.venv
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "virtualenv.pyz/__main__.py", line 168, in <module>
File "virtualenv.pyz/__main__.py", line 164, in run
File "virtualenv.pyz/virtualenv/__main__.py", line 18, in run
File "virtualenv.pyz/virtualenv/run/__init__.py", line 30, in cli_run
File "virtualenv.pyz/virtualenv/run/__init__.py", line 48, in session_via_cli
File "virtualenv.pyz/virtualenv/run/__init__.py", line 75, in build_parser
File "virtualenv.pyz/virtualenv/run/plugin/seeders.py", line 8, in __init__
File "virtualenv.pyz/virtualenv/run/plugin/base.py", line 39, in options
File "virtualenv.pyz/virtualenv/run/plugin/base.py", line 18, in entry_points_for
File "virtualenv.pyz/virtualenv/run/plugin/base.py", line 18, in <genexpr>
File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'virtualenv.seed.via_app_data'
This is the same end problem as #1873 but its a bit less under user control. They’ve downloaded the zipapp, run python virtualenv.pyz
and got bitten by the fact that python
already had virtualenv installed.
Over in Pants where we used to use the virtualenv.pyz to bootstrap a virtualenv for Pants we had to switch to using Pex to run virtualenv since Pex can create a zipapp with proper isolation from the underlying interpreter used to run the PEX zipapp: https://github.com/pantsbuild/setup/pull/99
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (5 by maintainers)
Top Results From Across the Web
zipapp — Manage executable Python zip archives — Python ...
Source code: Lib/zipapp.py This module provides tools to manage the creation of zip files containing Python code, which can be executed directly by...
Read more >Python's zipapp: Build Executable Zip Applications
Go back to your terminal window and run the following command: (venv) $ python -m zipapp realpython/ \ -o realpython.pyz \ -p "/usr/bin/env...
Read more >28.4. zipapp — Manage executable python zip archives
This module provides tools to manage the creation of zip files containing Python code, which can be executed directly by the Python interpreter....
Read more >path - Global development dependencies in python, aside ...
some script you run once mkdir -p ~/opt curl -o virtualenv.pyz ... I first download virtualenv.pyz which is a zipapp so I don't...
Read more >virtualenv 20.17.0 - PythonFix.com
Virtual Python Environment builder. ... sos installed into a virtualenv; The virtualenv.pyz zipapp cannot be run with an arbitrary python.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
A simple workaround that seems to work is to invoke python with the
-S
flag (“don’t imply ‘import site’ on initialization”)Ah, yes Windows (and Python 3.4). I’ll take a crack at a PR to fixup the existing zipapp main module as you suggest.
I do want to note that Pex does support all the rest though. For example (I use
--include-tools
andPEX_TOOLS=1
here just to have a concise way to demonstrate that multiple versions of distributions are contained in the PEX file and the right ones are activated for the respective interpreter):Under CPython 2.7:
Under PyPy (2.7):
Note that PyPy gets its own platform-specific wheel activated for scandir.
For CPython 3.5:
And for CPython 3.6:
Note that different versions of importlib-metadata and importlib-resources are embedded and chosen. Etc.