I'm working on a large project and am nearly done so I thought of installing pyinstaller so that I can convert the python script to an .exe file.
When I ran the .exe file, there was an error "Unhandled Exception.." basically saying that one of the directories I placed in the script to a file doesn't exist. The directory is:
'C:\\Users\\user\\AppData\\Local\\Temp\\_MEI45202\\Images\\SaveChangesButton.png'
This shouldn't be the directory though. Here is an alternative script that has the same problem (it's shorter):
import os
from PIL import Image
filepathforpythonfile = __file__
filepathforpythonfile = filepathforpythonfile.replace("Understanding OSModule.py", "")
filepathforpythonfile = filepathforpythonfile + "/Images/SaveChangesButton.png"
__file__ = os.path.abspath(filepathforpythonfile)
im = Image.open(__file__)
im.show()
It works perfectly fine. In fact if I run in the IDE print(__file__)
, the file directory of the image comes out perfectly.
When I use pyinstaller to convert the top to a .exe file, I get an error by the OS not the IDE. The directory comes out to \AppData\Local or something random I don't know.
Now, I must say my knowledge of paths and directory and the os module is very limited so bear with my ignorance. Many thanks in advance.
NOTE: Here "Understanding OSModule.py" is the name of the .py file. The image folder sits in the same folder as the .py file.