Reputation: 17
I have made a deep learning model which uses a folder of Images stored in a common directory FINAL, where both the python script of this code and the dataset folder Images exist. I want to convert the .py script to .exe executable windows application using PyInstaller (Auto-py-to-exe), followed by an installer creation using NSIS. All functions are working fine, except the path error.
As evident, the code below has the hard code for the path:
def resource_path(relative_path): #Installs relative path over hard-coded path for EXE file to work
""" Get absolute path to resource, works for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
model=1
path= resource_path(r'C:\Users\Nitin_Sethi-PC\Desktop\PS-I\FINAL\Images')
However, I want a relative path for the Images folder, as else the application created and installer setup can only work on my PC, and anyone who would want to run this program would have to update the path first, and make an executable using PyInstaller and then use NSIS.
I tried using the sys._MEIPASS function, however, was not able to achieve the desired result and need help in debugging the same. Here is the error message that needs to be resolved (although it has reference to the full code)
Traceback(most recent call last):
File "guifinal-exe.py", line 105, in <module>
File "guifinal-exe.py", line 57 in load_images_from_folder
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'C:\\\\Users\\\\Nitin_Sethi-PC\\\\Desktop\\\\PS-I\\\\FINAL\\\\Images\\\\Benign'
[8112] Failed to execute script 'guifinal-exe' due to unhandled exception!
Upvotes: 0
Views: 501
Reputation: 17
As suggested by furas, on changing the entire code
path= resource_path(r'C:\Users\Nitin_Sethi-PC\Desktop\PS-I\FINAL\Images')
to
path = resource_path(r'Images')
the issue is resolved provided that the Images(Dataset Folder) remains in the same working directory as the python script or executable program.
Upvotes: 1