I have struggling for too many hours on a problem occuring when converting a python project into an executable file.
Being not so familiar with executables, I am assuming that I need to execute my GUI file of my project but I am really struggling with the paths and all, now all my 8 python scripts and 4 csv files are all in the same directory.
When running the GUI.app (after using pyinstaller such as suggested at Include multiple data files with pyinstaller ) the file does not run and I get the error:
FileNotFoundError: File b'items_pro_processing.csv' does not exist
[25005] Failed to execute script GUI
logout
However, the file is there! All my python scripts and csv files are in the same folder. I have modified my spec file as follow to include all the csv files:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['GUI.py'],
pathex=['/Users/pierre/Desktop/exx'],
binaries=[],
datas=[('EvenPlast_historical_data.csv', 'EvenPlast_historical_data.csv'),
('items_pro_processing.csv', 'items_pro_processing.csv'),
('parameters.csv', 'parameters.csv'),
('Supplier_list1.csv', 'Supplier_list1.csv')],
hiddenimports=[items_pro_processing.csv'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='GUI',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=False,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
At this point, I have no clue what is going wrong, and I hope that a fresh eye could unblock the situation.
UPDATE:
as suggested by Barni in Bundling data files with PyInstaller (--onefile) I have added the following snippet of code to the file i want to turn into an exe.
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
for root, dirs, files in os.walk(resource_path("")):
print(root)
for file in files:
print( " ",file)
and then when I run the file I get this:
/Users/pierre/Desktop/exx/
items_pro_processing.csv
parameters.csv
dsjkfb.py
monthfor.py
EvenPlast_historical_data.csv
.DS_Store
Supplier_list1.csv
alerte_commande.py
items_file_processing.py
monthly_forecast.py
daily_forecast.py
ABCD_analysis_pre_processing.py
GUI.spec
GUI.py
metrics_fournisseur.py
replenishment_per_supplier.py
value_analysis_all.py
/Users/pierre/Desktop/exx/dist
GUI
/Users/pierre/Desktop/exx/dist/GUI.app
/Users/pierre/Desktop/exx/dist/GUI.app/Contents
Info.plist
/Users/pierre/Desktop/exx/dist/GUI.app/Contents/MacOS
GUI
/Users/pierre/Desktop/exx/dist/GUI.app/Contents/Resources
icon-windowed.icns
/Users/pierre/Desktop/exx/dist/GUI.app/Contents/Frameworks
/Users/pierre/Desktop/exx/__pycache__
daily_forecast.cpython-37.pyc
alerte_commande.cpython-37.pyc
ABCD_analysis_pre_processing.cpython-37.pyc
replenishment_per_supplier.cpython-37.pyc
metrics_fournisseur.cpython-37.pyc
value_analysis_all.cpython-37.pyc
GUI.cpython-37.pyc
monthfor.cpython-37.pyc
items_file_processing.cpython-37.pyc
monthly_forecast.cpython-37.pyc
/Users/pierre/Desktop/exx/build
/Users/pierre/Desktop/exx/build/GUI
Analysis-00.toc
PKG-00.toc
PYZ-00.toc
base_library.zip
warn-GUI.txt
EXE-00.toc
PYZ-00.pyz
BUNDLE-00.toc
xref-GUI.html
Tree-00.toc
Tree-01.toc
PKG-00.pkg
I feel like its progress already but I am struggling to interpret that output or more like, what to do with it.