1

I'm trying to put my Python program and all of it's dependencies into a single binary that could be executed from the command line. I followed Broken Man's suggestion in this post here using Cython3 and it works if you have a simple Python script. However it doesn't work if you're using import statements in your code to include your dependencies.

I'm looking for a solution that will allow me to execute my program similar to how you would in C, e.g think ./a.out

Please don't recommend using chmod +x to convert it into an executable. That's not what I'm looking for. This isn't a desktop app either - it needs to be executed from the command line.

Can Cython/Cythonize be used to compile dependencies or is there another tool that should be used for this? The dependencies I'm relying on are a mix of libraries installed with pip and custom written files in the same directory.

2
  • 1
    I think what you are looking for is pyinstaller. That creates an executable from your Python bytecode, plus the bytecode of all its dependencies, plus any binary extensions those dependencies need, plus a copy of the Python interpreter. Be warned, it will be pretty big and will take a noticeable while to load. Commented Aug 19, 2021 at 16:50
  • Concerning usage of cython for this problem: stackoverflow.com/a/59389683/5769463 Commented Aug 19, 2021 at 17:43

1 Answer 1

1

The tool you are looking for is Nuikta.

Syntax is: python -m nuitka --standalone --follow-imports programname.py where:-

--follow-import: Causes imported modules (including local imports) to be included in binary as well. --standalone: making standalone binary

Sign up to request clarification or add additional context in comments.

2 Comments

Nuitka is extremely slow. With just a simple hello world application, and with only click imported as a dependency, it takes my server approx. 21 min. to compile. With ccache configured. You're right, it does work. But currently its beyond any practical application. Therefore I am trying to get cython to work.
@HamzaZubair Cython doesn't handle dependencies and makes no claim to handle dependencies. It is genuinely the wrong tool for creating bundled applications.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.