shiv icon indicating copy to clipboard operation
shiv copied to clipboard

Ship the Python interpreter

Open alexprengere opened this issue 7 years ago • 10 comments

Hello, For the generated zipapp to be fully standalone, is it technically possible to ship the full Python interpreter along? This way you could deploy your app on environments with different or no Python interpreter.

alexprengere avatar May 15 '18 14:05 alexprengere

Hi @alexprengere,

Per the PEP, zipapps are zip files with a shebang at the top and a __main__.py file inside of them. This is the "magic" that allows the Python interpreter to be able to execute them. If the interpreter itself were included in the zipapp, it would no longer be a zipapp and would require some other mechanism to execute.

I believe there are some tools that ship the interpreter as well, pyinstaller comes to mind 🙂

lorencarvalho avatar May 15 '18 16:05 lorencarvalho

@sixninetynine You're absolutely correct! But pyinstaller is notoriously hard to configure compared to this.

This makes half of my deployment cycle (devops) a joke.

If it had this feature, I can't even comprehend the ease of deployment for django stuff..

Also the fact that this would enable us to ship python to mainstream users in a no-fuss way.

devxpy avatar Sep 14 '18 19:09 devxpy

Would there be a relatively easy way to combine shiv zips with portable distros like winpython zero?

albertogomcas avatar Oct 14 '19 07:10 albertogomcas

hi @albertogomcas

I'm not familiar with winpython, but from a cursory look at their project page and documentation it appears they provide a statically compiled Python interpreter.

In theory, running a pyz created by shiv using the winpython interpreter should work just fine. All a user would need to do is specify the shebang (using shiv's -p flag) or invoke the pyz using the winpython interpreter (e.g. C:\\path\to\winpython.exe your_pyz).

lorencarvalho avatar Oct 14 '19 14:10 lorencarvalho

PyOxidizer is the tool I'm currently evaluating for this.

warsaw avatar Oct 14 '19 17:10 warsaw

I tried to use PyOxidizer to run a shiv app unsuccessfully, did you manage to make them both work together?

tovmeod avatar Oct 16 '19 10:10 tovmeod

This article has some interesting story on shipping the interpreter. In short, it possible although with some caveats.

https://www.scylladb.com/2019/02/14/the-complex-path-for-a-simple-portable-python-interpreter-or-snakes-on-a-data-plane/

k4ml avatar Nov 18 '19 05:11 k4ml

At least on Linux, it is as easy as this:

# in a "shiv" working dir
$ tar xfz ~/tmp/egenix-pyrun-2.2.3-py3.5_ucs4-linux-x86_64.tgz ./bin/pyrun3.5
$ shiv -e shiv.cli:main -o shiv .
$ cat bin/pyrun3.5 shiv >bin/shiv
$ chmod +x ./bin/shiv 
$ ./bin/shiv 
…
  File "/home/jhe/src/github/shiv/bin/shiv/_bootstrap/__init__.py", line 86
    return root / f"{name}_{build_id}"
                                     ^
SyntaxError: invalid syntax

What happens here is that basically the bang path is replaced by an ELF binary which takes over execution of the appended ZIP. AFAIK, this also would work on Windows (given a compatible single-file release of Python).

Unfortunately PyRun currently only supports 3.5, and #124 prevents this from really working. Anyone know of other single-file Python releases?

jhermann avatar Jan 30 '20 13:01 jhermann

Python really need a portable (or standalone / one-file) executable file for Interpreter, but I could hardly find a nice choice.

As I known, the only way to use python without the installing process is copy the whole python install-folder between same linux distributions, or the Windows embed portable files.

ClericPy avatar Aug 01 '20 16:08 ClericPy

I think PyOxidizer is the leading contender here.

warsaw avatar Aug 03 '20 21:08 warsaw