OSError: Unable to open file (unable to open file: name = 'weight_res1.h5', errno = 2, error message = 'No such file or directory', flags = 0, o_flags = 0)

1,276 views
Skip to first unread message

Siddesh Dhakar

unread,
Jan 27, 2022, 4:27:04 AM1/27/22
to PyInstaller
Screenshot (143).pngMy Python script, application.py, uses weight_res1.h5 files  located in the same directory as application.py and throwing this error

bwoodsend

unread,
Jan 31, 2022, 3:58:33 AM1/31/22
to PyInstaller

And presumably your Python code references this file using something like

filename = "weight_res1.h5"

which assumes that weight_res1.h5 is in your current working directory instead of

import os
filename = os.path.join(os.path.dirname(__file__), "weight_res1.h5")

which assumes that weight_res1.h5 is next to you application.py? In which case your code is broken even without PyInstaller if you don’t set your working directory to the directory containing your code . There’s a bit more on the topic here.

Siddesh Dhakar

unread,
Feb 9, 2022, 3:07:37 AM2/9/22
to PyInstaller
Got it!
Thank you 

Reply all
Reply to author
Forward
0 new messages