I am having issues with a converted .exe file. It does not find my excel file.
I have the following code
import pandas as pd
import os
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
os.chdir(dname)
#Load data
data = pd.read_excel("data.xlsx")
...
The second part of the code (abspath, dname, os.chdir(dname) is setting the path to the location of the .py file. Hence, having the .py file and .xlsx file together will always make it find it no matter the location.
Then I convert it to .exe using
pyinstaller --hidden-import=pandas --onefile script.py
To make my script.py work, I have to have the data.xlsx file in the same folder as the script.py file.
I would assume dragging the .exe file out of the dir folder into the same location at as the .xlsx file would make it run but running the .exe files returns the following error:
Failed to execute script script. No such file 'data.xlsx' in directory.
How can I make it read my excel file no matter the location of the '.exe+.xlsx' folder?