I'm trying to make an executable file, using pyinstaller, with included files (json, logo, driver) which will work on any computer.
I've included several files in the executable through this line -
pyinstaller.exe --onefile --add-data "jsonfile.json;." --add-data "chromedriver.exe;." --add-data "logo1.ico;." --windowed --icon=logo1.ico script.py
SUCCESS BUT, when I opened it on another computer, does not work.
Also, I moved the files from the current directory on my computer and also not working - so something to do with the path I assume.
This code is for paths for any file included -
def resource_path(relative_path):
if hasattr(sys, '_MEIPASS'):
return os.path.join(sys._MEIPASS, relative_path)
return os.path.join(os.path.abspath("."), relative_path)
To that function, the path on my computer is sent. Any ideas what went wrong?
4 Things, none of which actually solve your problem, but might help
--add-data "data/jsonfile.json;./data/jsonfile.json"
os.startfile(sys._MEIPASS)
to open the folder and look at it (note you should put a sleep or a pause after because it will clean up the files when the program crashes or closes) resource_path("data/myfile.json")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.