May-15-2021, 11:01 AM
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]](https://zupimages.net/up/21/19/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]](https://zupimages.net/up/21/19/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
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]](https://zupimages.net/up/21/19/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]](https://zupimages.net/up/21/19/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: passinsertion 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