Python Forum
problem with pyinstaller to create an executable file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
problem with pyinstaller to create an executable file
#1
Hi;
I just created an application with python version 3.9.4: when I run the python file (index.py), it works fine without any problem. once i have converted this python file with pyinstaller version 4.3 with two methods:

first method: with the command under cmd: pyinstaller index.py

I have as result the "dist" folder containing the exe file and other files and subfolders like in this image.
[Image: lc4e.jpg]

second method: with the following command: pyinstaller —onefile index.py

I have a single index.exe file in the "dist" folder

[Image: 0e63.jpg]

when I run the index.exe file for the first method all is fine, and in particular there is creation of the folders for the database (under sqlite3)., while for the second method the executable file is executed correctly except there is no creation of database files

Is there a solution to this problem for the second method because I want the executable to be a single file rather than a whole folder spawning multiple files relating to the imported libraries.

function to create the files for the database, and save the data in Excel files

def copy_of_save_data(self):
        print("chemin d'acces a db cree.")
        path= os.path.dirname(os.path.realpath(__file__))#récupérer le répertoire courant
        # a) creations des  dossiers de sauvegarde de la base de données  pour l'ILs 35R :     
        os.makedirs(path+'\\data_save\\database\\ILS', exist_ok=True)
        print("data_save directory is created at \'\\data_save\\database\\ILS\'")
        # b)creations des sous dossiers de sauvegarde de copie pour l'ILs 35R :
        for loop in ('cev\\liste_corrections_totals','cev\\liste_corrections_confirmees','cev\\liste_corrections_cette_annee','cev\\liste_corrections_periode_choisie','alarmes_axe\\liste_alarmes_axe_totales','alarmes_axe\\liste_alarmes_axe_confirmees','alarmes_axe\\liste_alarmes_axe_ce_mois','alarmes_axe\\liste_alarmes_axe_cette_annee','alarmes_axe\\liste_alarmes_axe_periode_choisie','alarmes_faisceau\\liste_alarmes_faisceau_totales','alarmes_faisceau\\liste_alarmes_faisceau_confirmees','alarmes_faisceau\\liste_alarmes_faisceau_ce_mois','alarmes_faisceau\\liste_alarmes_faisceau_cette_annee','alarmes_faisceau\\liste_alarmes_faisceau_periode_choisie') :
            try:
                os.makedirs(path+'\\data_save\\datafile\\ILS35R\\loc35R\\'+loop)
            except OSError:
                pass
        for loop in ('cev\\liste_corrections_totals','cev\\liste_corrections_confirmees','cev\\liste_corrections_cette_annee','cev\\liste_corrections_periode_choisie','alarmes_axe\\liste_alarmes_axe_totales','alarmes_axe\\liste_alarmes_axe_confirmees','alarmes_axe\\liste_alarmes_axe_ce_mois','alarmes_axe\\liste_alarmes_axe_cette_annee','alarmes_axe\\liste_alarmes_axe_periode_choisie','alarmes_faisceau\\liste_alarmes_faisceau_totales','alarmes_faisceau\\liste_alarmes_faisceau_confirmees','alarmes_faisceau\\liste_alarmes_faisceau_ce_mois','alarmes_faisceau\\liste_alarmes_faisceau_cette_annee','alarmes_faisceau\\liste_alarmes_faisceau_periode_choisie') :
            try:
                os.makedirs(path+'\\data_save\\datafile\\ILS35R\\gp35R\\'+loop)
            except OSError:
                pass
        # c) creations des sous dossiers de sauvegarde de copie pour l'ILs 35L :
        for loop in ('cev\\liste_corrections_totals','cev\\liste_corrections_confirmees','cev\\liste_corrections_cette_annee','cev\\liste_corrections_periode_choisie','alarmes_axe\\liste_alarmes_axe_totales','alarmes_axe\\liste_alarmes_axe_confirmees','alarmes_axe\\liste_alarmes_axe_ce_mois','alarmes_axe\\liste_alarmes_axe_cette_annee','alarmes_axe\\liste_alarmes_axe_periode_choisie','alarmes_faisceau\\liste_alarmes_faisceau_totales','alarmes_faisceau\\liste_alarmes_faisceau_confirmees','alarmes_faisceau\\liste_alarmes_faisceau_ce_mois','alarmes_faisceau\\liste_alarmes_faisceau_cette_annee','alarmes_faisceau\\liste_alarmes_faisceau_periode_choisie') :
            try:
                os.makedirs(path+'\\data_save\\datafile\\ILS35L\\loc35L\\'+loop)
            except OSError:
                pass
        for loop in ('cev\\liste_corrections_totals','cev\\liste_corrections_confirmees','cev\\liste_corrections_cette_annee','cev\\liste_corrections_periode_choisie','alarmes_axe\\liste_alarmes_axe_totales','alarmes_axe\\liste_alarmes_axe_confirmees','alarmes_axe\\liste_alarmes_axe_ce_mois','alarmes_axe\\liste_alarmes_axe_cette_annee','alarmes_axe\\liste_alarmes_axe_periode_choisie','alarmes_faisceau\\liste_alarmes_faisceau_totales','alarmes_faisceau\\liste_alarmes_faisceau_confirmees','alarmes_faisceau\\liste_alarmes_faisceau_ce_mois','alarmes_faisceau\\liste_alarmes_faisceau_cette_annee','alarmes_faisceau\\liste_alarmes_faisceau_periode_choisie') :
            try:
                os.makedirs(path+'\\data_save\\datafile\\ILS35L\\gp35L\\'+loop)
            except OSError:
               pass
insertion code of the function in the constructor:
class MainApp(QMainWindow,Ui_MainWindow) :
    def __init__(self,parent=None) :
 
        super(MainApp,self).__init__(parent)
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.win_UI()          
        self.copy_of_save_data() 
at the end, for information, I have already introduced the code below at the very beginning of my application code before importing the PyQt5 libraries to remedy the current folder problem during the creation of the DB files:

###############################################################
# Fix qt import error : Include this file before import PyQt5 

def _append_run_path():
    if getattr(sys, 'frozen', False):
        pathlist = []
    
# If the application is run as a bundle, the pyInstaller bootloader
# extends the sys module by a flag frozen=True and sets the app
# path into variable _MEIPASS'.
        pathlist.append(sys._MEIPASS)

        # the application exe path
        _main_app_path = os.path.dirname(sys.executable)
        pathlist.append(_main_app_path)

# append to system path enviroment
        os.environ["PATH"] += os.pathsep + os.pathsep.join(pathlist)

    logging.error("current PATH: %s", os.environ['PATH'])

# appel de la fonction avant  PyQT5 : 
_append_run_path()

#  PyQT5 : 
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
.
.
.
thanks for your help
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create Choices from .ods file columns cspower 3 583 Dec-28-2023, 09:59 PM
Last Post: deanhystad
  Recommended way to read/create PDF file? Winfried 3 2,867 Nov-26-2023, 07:51 AM
Last Post: Pedroski55
  Use PM4PY and create working file thomaskissas33 0 645 Nov-14-2023, 06:53 AM
Last Post: thomaskissas33
  Create csv file with 4 columns for process mining thomaskissas33 3 745 Nov-06-2023, 09:36 PM
Last Post: deanhystad
  problem in using pyqrcode module to create QRcode akbarza 9 1,931 Aug-23-2023, 04:17 PM
Last Post: snippsat
  Using pyinstaller with .ui GUI files - No such file or directory error diver999 3 3,300 Jun-27-2023, 01:17 PM
Last Post: diver999
  Problem with Pyinstaller. No module named '_tkinter' tonynapoli2309 0 994 May-15-2023, 02:38 PM
Last Post: tonynapoli2309
  create exe file for linux? korenron 2 969 Mar-22-2023, 01:42 PM
Last Post: korenron
  my first file won't create itself MehHz2526 2 893 Nov-27-2022, 12:58 AM
Last Post: MehHz2526
  Create multiple/single csv file for each sql records mg24 6 1,384 Sep-29-2022, 08:06 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020