0

From a command prompt on Windows 11 with Python 3.8.10 I run the following pyinstaller command:

pyinstaller --onefile --windowed --add-data "solarpic.gif;." scratch.py

solarpic.gif is in the same folder as scratch.py, but I get an exception that reads:

Traceback (most recent call last):
    File "scratch.py", line 7, in <module>
    File "PIL\Image.py", line 3227, in open
    FileNotFoundError: [Errno 2] No such file or directory: 
    'solarpic.gif'

This is the code:

from tkinter import *
from PIL import ImageTk, Image
root=Tk()

picframe = LabelFrame(root)
picframe.grid(column=0, row=0, padx=10, 
pady=10,sticky=NSEW)
photo_image = Image.open('solarpic.gif')
img1 = photo_image.resize((600, 200))
photo_image = ImageTk.PhotoImage(img1)
piclabel = Label(picframe, image=photo_image)
piclabel.place(x=10,y=10)
piclabel.pack()
root.mainloop()

I've tried:

--add-data "solarpic.gif;."
--add-data "solarpic.gif;.gif"
--add-data "solarpic.gif;solarpic.gif"
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
MikeNH
  • 43
  • 2
  • 5
  • When do you get the exception - is it when you try to create the application with Pyinstaller, or when you try to run it, or just what? What happened when you tried the other variants of the `pyinstaller` command? – Karl Knechtel Jun 02 '23 at 01:54
  • Thanks for responding... The code compiles fine..no errors. The error occurs when I run the executable. If I put the file that was not found in the same folder as the executable, everything works fine. The other variants responded with the same error. – MikeNH Jun 02 '23 at 16:25

0 Answers0