How to create an executable for a python program that installs the used libraries?

Asked

Viewed 7,126 times

7

Hello, I have a code I made in python and it uses some libraries. I wonder if it is possible to make an executable for this program and q user q uses it n need to have python or these libraries installed.

  • 1

    Specify your problem better so that users can help you. If I can put the code you’ve tried so far it’s even better.

2 answers

11


Looks like you want to compilar your source code in an executable.


If your code has been written to python 2.x ou 3.0-3.1, you can use, for example, the library py2exe.

To create the executable, you must:

  1. install the py2exe (pip install py2exe)

  2. have the code to be compiled saved on the computer (for example the code hello.py)

  3. create a file called setup.py in the same folder as the code to be compiled, with the following content:

    from distutils.core import setup
    import py2exe
    
    setup(console=['hello.py'])
    
  4. Browse the terminal to the folder with the files (hello.py and setup.py) and rotate the command python setup.py install

  5. Done. In the folder 2 new folders must have been created. In one of them you will find yours .exe.

OBS:

  • 1) You can see in the documentation more parameters to add when compiling;

  • 2) If your code has been written to Python 2.6, 2.7, 3.0 ou 3.1, you should pay attention to the fact that the py2exe does not automatically include the DLL MSVCR90.dll in the briefcase dist, so you should put it there manually.


If your code has been written to python 2.7 ou 3.3—3.5, you can use, for example, the library PyInstaller.

To create the executable, you must:

  1. Install the package pyinstaller (pip install pyinstaller)

  2. To create the . exe, navigate through the terminal to the folder with the code to compile and type:

    pyinstaller --onefile script.py
    
  3. Ready.

4

You can also use the cx_freeze to "package" your program and generate an executable.

A friend and I created a graphic version for the compiler using the library a while ago Tkinter, that you can find in my Github.

Browser other questions tagged

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