Simplify compilation of complete applications
See original GitHub issueIt can be useful in some cases to compile a complete application into a single binary. Currently, this is difficult to do with Cython and involves several manual steps. Since most of this can be automated, there should be a tool for it.
A part of this is already implemented in the form of the cython_freeze tool and the BuildExecutable helper. Stitching it together into an easy to use “here’s my code, drop the binary here” tool should not be all too difficult. Also take a look at Nuitka, which reportedly has a good way of dealing with this.
Also see #2849 regarding the integration of cython_freeze
into cython --embed
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Toward Simplifying Application Development, in a Dozen ...
Lesson 12: To simplify application development to the point of being accessible to the entire population, the tools must act like hands-on ...
Read more >Developing a Competitive SAMHSA Grant Application
In preparation for starting the grant application process, make sure your program/organizational information is up-to-date and that you have compiled statistics ...
Read more >The Simplification Principle - Deloitte
The following sections of this paper will provide more comprehensive insight into how we can apply the principle to organisations and processes, and...
Read more >Simplify - Apps on Google Play
Experience the new WiFi with Simplify. Buy and sell your mobile data easily. Forget about getting a travel SIM card or expensive data ......
Read more >Using PyInstaller to Easily Distribute Python Applications
How PyInstaller can simplify application distribution; How to use PyInstaller on your own ... Package your entire application into a single executable file....
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
Let’s get back to this issue with more concrete details.
In PEP489, I read that a compiled module
pack.mod.sub
should be inpack/mod/sub.so
with an initialization functionPyInit_sub
. When embedding modules, we want them to become ‘built-in’ modules, which we achieve throughPyImport_ExtendInittab
(as done incython_freeze
).This is where @jdodds is not entirely correct, as these built-in modules need not live at the toplevel (they can form a hierarchy). However, when using the default initialization function names (
PyInit_<modulename>
), there will be a naming collision between the initialization functions ofpack.mod.sub
andother.sub
. Both functions will be namedPyInit_sub
.It is possible to solve this without really breaking anything. For this, we need
Cython/Compiler/ModuleNode.py:mod_init_func_cname
to output theapi_name
instead when aiming for built-in modules. Theinittab
should then simply refer to thesePyInit_<api_name>
functions instead. The point is that we can use any function name we want in theinittab
and this should somehow become unique for every module.What is left, then, is to decide how to expose this functionality. With
--embed-modules=
of #2849, we can usePyInit_<api_name>
, bun this means that we can only link to libraries built specifically for this purpose. Maybe something likecython --built-in pack/mod/sub.py
should generate code with the API-name as the name of the initialization function.I’ve run into two major issues when trying to use Cython to take a python codebase and create a single binary, some of which I’m sure are due to gross ignorance on my part:
As far as I know, there isn’t such a thing as a package-aware c extension in python, so if you’re, for example, running
cython_freeze
over the codebase of an application that contains multiple packages you need to include a step where you flatten that namespace. This isn’t too hard to do in codebases that don’t do much in__init__.py
files for example, but is much more difficult to guarantee in the general case.Related to the above, it’s difficult to account for third-party dependencies. They still need, in general, to be shipped alongside the executable. Py2exe has an extension that allows for python to load dynamic libs from a zipfile, and also the capability to pack that up into a single executable, I’m not aware of a working way to do that on systems other than windows.