by BiteCode_dev · 6y ago · 0 comments
We even how have a nice tool to automate the bundling for you:
https://pypi.org/project/shiv/
Of course you still have to figure out how to get a Python installed on the final machine, that's the price to pay to be an interpreted language.
We don't have yet a story to ship a beautiful exe/dmg/deb/rpm that embeds the zipapp and libpython in an easy way.
This is a non-trivial thing to handwave away.
Using an interpretted language always leads to this.
I know no popular interpretted language with a seamless experience to ship a standalone exe.
In fact, Python is probably the one with the best story here, since it has nuitka (https://nuitka.net/), which allows to compile Python code into a fully standalone exe.
But then you need to install a compiler, headers, etc. And no cross compilation of course. Not to mention on Linux, you have to ensure you target the lowest version of libc you can.
You are still very far from Go or Rust, and I'm hoping one day that RustPython will succeed because that would mean an amazing deployment story.
Meanwhile, you trade the ease of deployment of compiled languages for the ease of development of interpretted ones.
I think it's a fare trade for most people: you dev the program much more often that you deploy it.
That doesn't mean we shouldn't work, as a community, to improve the deployment story. It's a serious hindrance.
That's the raison d'être of the Briefcase project (https://beeware.org/project/projects/tools/briefcase/). It's still in progress, but the last prez I saw on it was quite impressive already.
Isn't RustPython just an alternative interpreter to CPython, implemented in Rust instead of C?
How would RustPython offer better deployment than CPython?
So if one day RustPython gets compatible enought with CPython that you can use it as a drop in replacement, you can start creating a tool that compiles any Python VM for any target, and bring along your program with it. Making a standalone version of it would become much easier.
Right now, doing so either requires you to bring in a pre-compile version of cpython for your target (which is what briefcase does) or compile the thing yourself with gcc + headers + deps(which is what nuitka does).
It's not easy.
I don't know exactly how it goes but I'm pretty sure it's a horror story.
That being said, a lot of extensions are pre-compiled and provided as wheel, which is the case for tensorflow (I don't know for CUDA, I can't test on a laptop without a GPU).
Let's see what this means:
$ py -m venv test
$ test\Scripts\activate
$ pip install tensorflow
$ code hello_tensor.py
# import tensorflow as tf
# def main():
# with tf.compat.v1.Session() as sess:
# a = tf.constant(3.0)
# b = tf.constant(4.0)
# c = a+b
# print(sess.run(c))
Now with shiv: $ copy hello_tensor.py test\Lib\site-packages
$ shiv -e hello_tensor.main --site-packages test\Lib\site-packages\ -o hello_tensor.pyz
$ python hello_tensor.pyz
...
2020-05-28 17:31:46.580704: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
7.0
So it works fine, but remember:- it will only run on the system this particular wheel has been designed to run on. In my case cp38-win_amd64.
- it will come bundled with tensorflow, which is a behemot, meaning your hello world pyz will around 500 Mo.
- it needs to unzip, so the first run will be REALLY slow
For something like this, I would advice a more generic deployment tool, like fabric 2 if it's remote, or a make-like tool such as doit if it's local only.
Make your deployment script, and zipapp that.
If so, the extraction is going to make startup very slow. If not, that’s just messy. Either way, it’s not ideal.
Yes, it's not ideal.
But it beats shipping your entire dev env to the server.
I find it a good compromise. The extraction is done is $HOME/.shiv/{zipappname}_{zipapphash} so it's not a horrible mess. But if your project is big, you do have to clean up the old install because it can eat a significant amount of space.
For you regular cmd tool though, it's a blip.
Also for Java. The installs usually include their own favorite version of Java alongside the actual application.