New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify compilation of complete applications #2011

Open
scoder opened this Issue Nov 18, 2017 · 4 comments

Comments

Projects
None yet
3 participants
@scoder
Contributor

scoder commented Nov 18, 2017

It 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.

@jdodds

This comment has been minimized.

Show comment
Hide comment
@jdodds

jdodds Nov 20, 2017

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:

  1. 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.

  2. 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.

jdodds commented Nov 20, 2017

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:

  1. 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.

  2. 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.

@ha11owed

This comment has been minimized.

Show comment
Hide comment
@ha11owed

ha11owed Jan 28, 2018

+1

I currently have the issue of not being able to define packages with PyImport_ExtendInittab.
With better support for this, it would not be necessary to flatten the namespaces.

ha11owed commented Jan 28, 2018

+1

I currently have the issue of not being able to define packages with PyImport_ExtendInittab.
With better support for this, it would not be necessary to flatten the namespaces.

@jdodds

This comment has been minimized.

Show comment
Hide comment
@jdodds

jdodds Feb 21, 2018

@ha11owed that's something that's a limitation of Python's C API and is out of Cython's hands as far as I'm aware. If it's possible to create a Python C extension that is seen as a package while being built into the interpreter I'd be glad to put in work getting that into Cython.

jdodds commented Feb 21, 2018

@ha11owed that's something that's a limitation of Python's C API and is out of Cython's hands as far as I'm aware. If it's possible to create a Python C extension that is seen as a package while being built into the interpreter I'd be glad to put in work getting that into Cython.

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Mar 17, 2018

Contributor

Copying the PyInstaller+Cython tutorial link from #2147 here for future reference:
https://github.com/mobiusklein/cython_pyinstaller_example

Contributor

scoder commented Mar 17, 2018

Copying the PyInstaller+Cython tutorial link from #2147 here for future reference:
https://github.com/mobiusklein/cython_pyinstaller_example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment