2

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.

Murcielago
  • 905
  • 1
  • 8
  • 30
  • There’s a snippet of code in my answer to this question which will show you what files are actually included in your pyinstaller executable, and where they are https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile/54881911#54881911 – DisappointedByUnaccountableMod Feb 08 '20 at 21:27
  • And the problem isn’t with PyInstaller, it’s that your code when running in a PyInstaller executable can’t find a file it expects to be in a certain location – DisappointedByUnaccountableMod Feb 08 '20 at 21:29
  • Thank you! and potential dumb question where do I need to put the resource path() snippet of code – Murcielago Feb 08 '20 at 21:31
  • In the same file as the snippet (which should run in main()) – DisappointedByUnaccountableMod Feb 08 '20 at 21:32
  • I have done that, the purpose was to know where to move my files to correct? I am still a little bit confused why it would not work if they are all in the same directory, and my "imports" in the code are all fine – Murcielago Feb 08 '20 at 21:54
  • Which directory does your code try to open the code in? You probably need to use `resource_path()` to get the new path to the file. By using `resource_path()` your code should work as a script and also as a pyinstaller executable. – DisappointedByUnaccountableMod Feb 08 '20 at 22:06
  • i have just updated my post to include the updated situation – Murcielago Feb 08 '20 at 22:14
  • Is this what you get when you run the pyinstaller executable? If it isn’t, create your executable and show the output when you run that. Also, include the _full_ stacktrace of the error message in your question. What folder are you loading the file from? Are you using the current directory? This is __different__ when the pyinstaller runs, which is why you should use `resource_path()` to get the correct path. – DisappointedByUnaccountableMod Feb 08 '20 at 22:53
  • i have finally found out what is messing up. resource path is a function that goes into my files, and they need the csv files to work. and then the output of all these files go into the GUI file that I try to get as an executable. So resource_path creates a circular reference because i have input and output in the same file. How can I work around this problem? As an example, I use pd.read_csv("output of resource_path") in my files – Murcielago Feb 09 '20 at 14:34

1 Answers1

0

I don't know if it's a copy/paste mistake but in your line

hiddenimports=[items_pro_processing.csv'],

you have missed a '

Julien Drevon
  • 322
  • 2
  • 17