15

I need a program to compile python source code; as I found out at first I need to make a binary file from my python script.

I've already checked a lot of links, but still I haven't found something for Linux.

I found py2bin for OS/X, but there are no versions for Linux.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
TrueBad0ur
  • 193
  • 1
  • 1
  • 7

2 Answers2

8

In my opinion your problem in Google stems for calling a compiler capable of producing binaries from python a "disassembler".

I have not found a true compiler, however I have found in Google a python compiler packager, which packs all the necessary files in a directory, obfuscating them, with an executable frontend: pyinstaller at http://www.pyinstaller.org/ ; it appears to be actively supported, as the last version 3.4 which was released on 2018-09-09, contrary to py2bin which seems to be not actively maintained.

Features:

  • Packaging of Python programs into standard executables, that work on computers without Python installed.
  • Multi-platform, works under:
    Windows (32-bit and 64-bit),
    Linux (32-bit and 64-bit),
    Mac OS X (32-bit and 64-bit),
    contributed suppport for FreeBSD, Solaris, HPUX, and AIX.
  • Multi-version:
    supports Python 2.7 and Python 3.3—3.6.

To install:

pip install pyinstaller

Then, go to your program’s directory and run:

pyinstaller yourprogram.py

This will generate the bundle in a subdirectory called dist.

GC 13
  • 556
  • 4
  • 13
Rui F Ribeiro
  • 55,929
  • 26
  • 146
  • 227
  • 4
    pyinstaller doesn't compile python programs, it just pack so that the result package can be used like a binary package. So practically an extractor and execution of normal python. (it use pyc, so simple reverse engineering is difficult, but a tools that change identifier should also be used, if reverse engineering is to avoid). – Giacomo Catenazzi Feb 20 '18 at 14:46
  • @GiacomoCatenazzi Thanks, I already suspected that. I also suspect it to be the case of `py2bin`, you can place scripts/python/perl programs under a "binary" package in MacOS. – Rui F Ribeiro Feb 20 '18 at 14:49
  • 2
    I doesn't know. On older time, there where a python to C (+compiler) (py2bin is so old, so maybe...). Cython could be a solution, but I doesn't know if and how the code should be modified (so it will be no more pure Python). – Giacomo Catenazzi Feb 20 '18 at 14:57
  • @GiacomoCatenazzi Thanks for your insights. – Rui F Ribeiro Feb 20 '18 at 15:04
  • The referenced site is no more – FractalSpace Mar 09 '22 at 13:18
  • @FractalSpace thanks will monitor this. In the meanwhile, there is a page at https://pyinstaller.readthedocs.io/en/stable/ – Rui F Ribeiro Mar 09 '22 at 13:42
  • 1
    @Rui, yes, that one worked – FractalSpace Mar 09 '22 at 14:51
4

Try Nuitka. It takes a .py and then creates a .bin. It works on Gnu+Linux and is in most popular distribution's software repositories.

Nuitka is a Python compiler written in Python.

It's fully compatible with Python 2.6, 2.7, 3.3, 3.4, 3.5, 3.6, and 3.7.

You feed it your Python app, it does a lot of clever things, and spits out an executable or extension module.

Free license (Apache).

https://nuitka.net/pages/overview.html

9716278
  • 151
  • 5