soezel / python-project

School Project lol
1 stars 0 forks source link

A example of how to make a .exe file out of a .py script. #3

Closed Luwey-Silva closed 4 months ago

Luwey-Silva commented 1 year ago

A example of how to make a .exe file out of a .py script.

Step 1. - Set the name of the file "setup.py" and import all the libaries you have used in the project.

Hint: better set a env and donwload all the libraries there. So you don't have do compile the .exe files with the whole big amout of libraries installed on your computer.

import sys
import os
from cx_Freeze import setup, Executable  ---------> always import this.
import customtkinter
import PIL
import tkinter
import openpyxl
from tkcalendar import Calendar, DateEntry
from PIL import ImageTk, Image
from docxtpl import DocxTemplate
import datetime
import docx2pdf

Step 2

#ADD Files
files = ["XReports_APP_icon.ico", "UI_1.png"] ---> Add the extra files of your project in this variable. (PNGs, ICOs, etc...)

#TARGET
target = Executable(
    script="main.py", --> set here the name of you python script.
    base="Win32GUI",
    icon="XReports_APP_icon.ico" --> and here the icon, if you do have one.
)
#SETUP
    setup (

    name="XReports APP",       #--> Set the name of the APP

    version="1.0",       #--> Set the Version number

    description="XReports APP - User",      #--> Set the  description

    author="User",      #--> Set the name of the author of the APP

    options={'build_exe': {'include_files': files}},
    executables=[target]
)
### Resume...

This code imports necessary libraries and modules, sets up the configuration for building an executable, 
and defines the target executable. It includes files "XReports_APP_icon.ico" and "UI_1.png" to be included in the build.

The target variable represents the main executable script "main.py".
It specifies the base as "Win32GUI" (indicating a graphical user interface) and sets the icon to "XReports_APP_icon.ico".

The setup function is called with various parameters to configure the build. 
It specifies the name, version, description, and author of the application. 
The options parameter includes the files specified in the files list. 
Finally, the executables parameter defines the target executable.

Step 3- To compile, open your terminal, go to "Setup.py" directory and run the comand:

"python setup.py build"

soezel commented 1 year ago

Thank youuuu