The "create a pyz of shiv using shiv" example doesn't work
See original GitHub issueAs written, the example leaves the shiv pyz file with a shebang pointing at the (presumably temporary) virtual environment used to build it.
The example should probably include a -p "/usr/bin/env python3"
argument to specify an explicit interpreter.
Actually, given that shiv pyz files are self-contained, there’s no real benefit to them ever having shebangs that refer to a virtualenv - maybe it would be worth making the default shebang /usr/bin/env python3
, or at least locate the “base” Python interpreter for a virtualenv - which can be done as
Path(getattr(sys, 'real_prefix', sys.base_prefix)) / Path(sys.executable).relative_to(sys.prefix)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (11 by maintainers)
Top Results From Across the Web
shiv — shiv documentation
Shiv is a command line utility for building fully self-contained Python zipapps as outlined in PEP 441 but with all their dependencies included!...
Read more >Creating Python app using shiv - Medium
Shiv creates a zipped file .pyz with all the needed dependencies packaged inside. The .pyz file can be then transported to other machine...
Read more >Dissecting a Python Zipapp Built with Shiv | Lincoln Loop
Enter Shiv. This downloads awscli and all its dependencies from PyPI and creates a zipapp ( aws. pyz ) which will run a...
Read more >Packaging - Discussions on Python.org
Thinking about Pip plans to introduce an alternative (zipapp) deployment method and how that may lead to Provide a `py run`/`py z` ...
Read more >shiv - PyPI
You can even create a pyz of shiv using shiv! python3 -m venv . source bin/activate pip install shiv shiv -c shiv -o...
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 FreeTop 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
Top GitHub Comments
Yeah, that looks really good. Tested on Windows using virtualenv and venv and it seems fine.
Ah, yes. My mistake - I didn’t test it properly.
The problem is that you need to get from the virtualenv/venv back to the original base installation. That’s what
sys.base_prefix
gives you (for a venv) andsys.real_prefix
(for a virtualenv). So all the getattr stuff is covering both bases there.But they give you the equivalent of
sys.prefix
, notsys.executable
. And the executable gets put in various places - what I was trying to do was avoid hard coding the fact that it’s inScripts/python.exe
on Windows, andbin/python
on Unix. But that’s for virtual environments, and the whole point here is to get a non-virtual location. So I was being dumb. What you actually need is justThat’s for Windows - of course, you’ll need to miss of the
.exe
suffix on Unix, and maybe do something aboutpython2
vspython3
- and maybe Python isn’t even insys.prefix
, but in/usr/bin
or/usr/bin/local
…? Or get everyone to switch to Windows where it’s simple 😉The more I think about it, the more I’d go for
#!/usr/bin/env python3
(use “python3” or “python2” depending onsys.version_info
). The Windows launcher handles that, and (hopefully!) it’s reliable on Unix.Or maybe even do what zipapp does, and default to no shebang, forcing the user to run the pyz as
python xxx.pyz
or be explicit about what they want via-p
.