0

I'm a newbie using python, I'm trying to create a .exe from a .py file. But, when I create this .exe, It only work if the images are in the same folder as the .exe file( but on the prompt code that a I use I think that it would compact everything together ). I read some topics here about it, but I didn't find the reason for this error.

pyinstaller -y -F -w -i "C:/Users/silvag1/Desktop/final/mc.ico" --add-data "C:/Users/silvag1/Desktop/final/photo.png";"." --add-data "C:/Users/silvag1/Desktop/final/mc.ico";"."  "C:/Users/silvag1/Desktop/final/final.py"

I thought that if I use the --add-data, everything would be compacted in a single file.

I've already read Bundling data files with PyInstaller (--onefile) but I didn't understand. So, just to be clear, my purpose is create only one file( a .exe) using a .py.

martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0
  • Remove the -add-data & it's argument
  • Build the .exe as you normally do
  • After you do, You'll have a dest folder & .spec file
  • The data is added to the spec file, you'll find there an array of data called analysis
  • add your image path & escape the slashes as you see in the file
  • use pyinstaller to build & this time build the .spec file, it will work

another way to do this is here, (I didn't test)

Ahmed I. Elsayed
  • 2,013
  • 2
  • 17
  • 30
  • Hi @Ahmed I. Elsayed, I've created a .exe from the .spec file, as you said, but an error appears when I try to execute, "Failed to execute script (program name)". I think it's because in my code, to select the figures I use: image = tk.PhotoImage(file ="photo2.png") I think that the program is trying to find this imagine in the current folder. Do you know how to fix it? – Gabriel Danilo Nov 05 '19 at 16:43