how to compile a python script in a executable

Asked

Viewed 9,963 times

2

How best to compile a python script for an executable running on a linux (Ubuntu), windows and mac operating system.

2 answers

4


In Windows you can compile Python . py scripts into . exe executables using Pyinstaller along with Pywin32:

Follow here the download links:

Pyinstaller: https://www.pyinstaller.org/

Pywin32: https://github.com/mhammond/pywin32/releases

You will download the zipped Pyinstaller, just smash its folder, and put it inside the Pyhon folder.

The command to compile is the following: (Where you have the ... you put the complete directory where the Python folder, Pyinstaller, is from, for example: C: Python3 pyinstaller-2.0 pyinstaller.py)

python C:... pyinstaller.py script.py

You can also compile online on this following website: http://py2exe.org/

  • and for linux, there is some way?

  • To generate binary only use the -F parameter, e.g.: $ pyinstaller -F script.py As for the operating system, to generate a . exe, you need to build on Windows, to generate a binary (Linux) you need to do this build on some Linux distro, and the same for Macos

-2

Using linux you can use the terminal.

python meuscript.py

It is the most basic form without using IDE. You can also specify the interpreter version. Here for example I use

python3 meuScript.py

An alternative is using Jupyter Notebook where you can run a scrip line by line and go seeing the results.

Or using an IDE even.

  • 1

    That’s not what he wants. He wants to package the script along with the modules and files needed for the program to run in a single file. For example for the person not having to manually install the modules needed for the program to run.

  • yes, that’s exactly it. I want to package the program so that the end user doesn’t have to install anything.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.