24

Is it possible to build a single-binary or single-directory package with PyInstaller that uses pypy as interpreter?

Any special tricks to do that?

Some alternative to PyInstaller?

If not, what are the fundamental technical reasons?

Notes why/how pyinstaller doesn't doesn't with pypy out of the box:

  • distutils.sysconfig.get_config_h_filename missing, fixed in pytinstaller trunk
  • (distutils.|)sysconfig.(_|)get_makefile_filename missing, actually optional
  • tries to link against libpython2.7.so.1, pypy in single executable, not a shared object
Dima Tisnek
  • 11,241
  • 4
  • 68
  • 120
  • P.S. I'm also open to binary patching tools (alin to `LD_PRELOAD` but resulting in single library), if someone can make a demo :) – Dima Tisnek Mar 03 '14 at 09:33
  • A [list](http://www.freehackers.org/Packaging_a_python_program) of alternatives to `PyInstaller` – VivienG Mar 06 '14 at 12:39
  • 1
    Thanks, @VivienG, sadly none of these claim to support `pypy`. – Dima Tisnek Mar 07 '14 at 10:50
  • A possible reason for that lack of support could be the fact that, pypy's JIT doesn't make sense with pre-built (meaning pre-compiled) binaries, leading to pyinstaller (or any 'packager') defeating the most common benefits of pypy i.e. performance gains because of JIT. – 0xc0de Aug 15 '21 at 05:30

1 Answers1

13

I have tried this out and it failed, on many occasions, because PyPy is only able to work with a few subset of what CPython uses. PyInstaller is a full blown CPython application, so there are not able to communicate.

PyInstaller's mechanism is sensitive to how CPython works, so PyPy can introduce some issues. This is what you'll get when trying to run PyInstaller in a PyPy virtual environment:

OSError: Python library not found: Python, .Python, libpython3.5.dylib,
libpython3.5m.dylib

This would mean your Python installation doesn't come with proper library files.

This usually happens by missing development package, or unsuitable build
parameters of Python installation.

* On Debian/Ubuntu, you would need to install Python development packages
  * apt-get install python3-dev
  * apt-get install python-dev
* If you're building Python by yourself, please rebuild your Python with
  `--enable-shared` (or, `--enable-framework` on Darwin)

If you need improved speed and hiding your code away from people, you can try out Cython. I use both Cython and PyInstaller a lot, and I love their cross platform nature.

When you are through with both, you can then use PyInstaller & CPython to package your app.

iChux
  • 2,266
  • 22
  • 37
  • 1
    Good point, although most on pyinstaller is pure python ran at user app build time, there's also `bootloader`. Quick inspection shows that it's mostly a collection of simple C-level hooks targeting CPython internals, but there's also a bit of complex stuff, run-time buinding to interpreter builtin types, on demand unpacking of user `py/pyc/pyo` files. – Dima Tisnek Mar 07 '14 at 09:01
  • 1
    You're right. I try as much as I can to avoid much of those problem when I'm on tight schedule to deliver. That's why I use the method I outlined above for you. – iChux Mar 07 '14 at 11:32