1

I am trying to create a python 3.7.7 based application on Mac OS Catalina 10.15 using pyinstaller 3.6. I installed python using Homebrew and pyinstaller with pip.

This python code, named GUI.py, needs five images that are stored in a folder named "resources" and everything is within the "Project" folder. So the structure of the project is like follows:

Project:

  • GUI.py
  • resources:
    • image1.png
    • image2.png
    • image3.png
    • image4.png
    • image5.png

The path that GUI.py uses to locate the images is like "resources/image1.png", "resources/image2.png" and so on for the rest of the images.

I open a terminal and type the following:

pyinstaller --add-data /Users/user/Desktop/Project/resources/*:resources /Users/user/Desktop/Project/GUI.py

Then the dist and build folders are created as well as the GUI.spec file.

The problem appears now when i go to the dist/GUI folder and i find the executable. I double click it to open my application but the following error appears:

FileNotFoundError: [Errno2] No such file or directory: 'resources/image1.png'

However, if i open the terminal and go to the dist/GUI directory where the GUI executable is located and execute it manually:

./GUI

it works perfectly and the application is opened.

It happens the same when i add the option --nocnosole to the pyinstaller instruction:

pyinstaller --add-data /Users/user/Desktop/Project/resources/*:resources --noconsole /Users/user/Desktop/Project/GUI.py

This creates a Mac OS application named GUI that does not open when i dobule click it. But, just as before, if i open a terminal and go to GUI/Contents/MacOS/ i find the GUI exectuable and execute it manually:

./GUI

then it works fine.

I don't know if i am adding correctly the resources folder containing the images or if it is a Mac OS problem with pyinstaller.

I add some notes with extra information:

  • I made the same whole process in Windows 10 and Ubuntu 18.04.1 and it works perfectly. I can create the executable contained in the dist folder and export it to other computers and it just works.
  • I used a different way to add data in the pyinstaller command and still it does not work: pyinstaller --add-data /Users/user/Desktop/Project/:. /Users/user/Desktop/Project/GUI.py
  • I followed the solutions provided in Pyinstaller adding data files but nothing works
  • The python application is a graphic user interface that uses tkinter, pyserial and PIL. Also, i used custom packages that i add with the -p option in the pyinstaller command but ommited here as it is not a source of errors.

I looked everywhere for a solution, read the documentation that pyinstaller provides referring to adding data but i found nothing.

1 Answers1

1

This is less of a python issue and more of a Mac one. When you start an application on a mac, the directory where the app is started is actually "/.app/Contents/MacOS/". My guess would be that either you need to place your resources directory in that location, so that the app can find it when it starts up, or you need to find a way to use direct pathing rather than the relative pathing that it appears you're using. I'm not all that familiar with pyinstaller, but my guess would be something like this, given the syntax you've used above:

pyinstaller --add-data /Users/user/Desktop/Project/resources/*:/LibraryDir/PythonStuff/resources /Users/user/Desktop/Project/GUI.py
Fubar
  • 251
  • 2
  • 8
  • Thank you for your answer I will try this. just a question, what do you refer to with /LibraryDir/PythonStuff? yeah I know it's a generic path but applied to the .app folder? what I've read from documentation explains that, in this case, /Users/user/Desktop/Project/resources/* is the source path (all the files within the resources folder) and /LibraryDir/PythonStuff/resources is the destination path , so this puts "resources" folder within the .app? the MacOS folder? thank you – Javier Pina De Paz Apr 20 '20 at 11:05