17

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.

7
  • Python 2 or Python 3? Also, is Nuitka or dis closer to what you want? Commented Feb 20, 2018 at 13:11
  • Cython is a popular optimizing static compiler for Python. Commented Feb 20, 2018 at 13:15
  • wiki.python.org/moin/Freeze That method will compile executables for *nix systems. Although I'm not sure if that's what you want. Commented Feb 20, 2018 at 13:17
  • disassembling python code? Commented Feb 20, 2018 at 13:22
  • Unless you mean create "precompiled" python modules (.pyc)? Commented Feb 20, 2018 at 13:34

2 Answers 2

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.

7
  • 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). Commented Feb 20, 2018 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. Commented Feb 20, 2018 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). Commented Feb 20, 2018 at 14:57
  • @GiacomoCatenazzi Thanks for your insights. Commented Feb 20, 2018 at 15:04
  • 1
    @Rui, yes, that one worked Commented Mar 9, 2022 at 14:51
5

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

1
  • Nuitka is Extremely Extremely slow. Slow beyond practical use. Commented Aug 24, 2021 at 12:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.