Lavínia Beghini
Lavínia Beghini

Reputation: 285

App generated with PyInstaller does not find files after building for MacOS

I've created a Mac OS Catalina virtual machine at Oracle VM VirtualBox, and tried to build my application running PyInstaller.

Here is the app.spec file:

# -*- mode: python ; coding: utf-8 -*-

block_cipher = None

added_files = [
        ('resources/data', './resources/data'),
        ('resources/icons', './resources/icons')
]

a = Analysis(['app.py'],
              pathex=['/Users/lavinia/Documents/GraphFilter'],
              binaries=[],
              datas=added_files,
              hiddenimports=[],
              hookspath=[],
              runtime_hooks=[],
              excludes=[],
              win_no_prefer_redirects=False,
              win_private_assemblies=False,
              cipher=block_cipher,
              noarquive=False)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)

exe = EXE(pyz
          a.scripts,
          [],
          exclude_binaries=True,
          name='app',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False , icon='resources/icons/hexagon.ico')
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               upx_exclude=[],
               name='app')
app = BUNDLE(coll,
             name='app.app'
             icon='resources/icons/hexagon.ico',
             bundle_identifier=None)

You can see that in the added_files variable I am describing the path for some files that my application requires.

Then I ran:

pyinstaller app.spec

However, after it finishes building and executing the app.app in the dist folder, the distribution does not work. Executing from inside the generated folder app the executable console application to see if I could find some errors, it prompts that the "resources/data/data_dictionary.json" was not found.

Looking in the folder, I can find the resources folder in the same folder where the application is, and the file is inside the folder, as expected.

I don't know any ways to debug it.

Upvotes: 0

Views: 1508

Answers (1)

Lavínia Beghini
Lavínia Beghini

Reputation: 285

I was finally able to generate the app file with the following configurations:

  • python3.8.12 installed from pyenv
  • pyinstaller 5.0.dev0 installed from dev branch

Then, at the main python file, I added the following:

import os
os.chdir(sys._MEIPASS)

It won't work to execute it locally, but it works with pyinstaller.

I've created a spec file using the following:

pyi-makespec --windowed --add-data "./resources/data:resources/data" --add-data "./resources/icons:resources/icons" --name GraphFilter --onefile --icon ./resources/icons/hexagon.icns app.py

Then run pyinstaller:

pyinstaller GraphFilter.py

And that's it!

Upvotes: 1

Related Questions