I am having an issue reading files with exe file after using pyinstaller module to create EXE
file from my script.
The whole error is;
Traceback (most recent call last):
File "mainf.py", line 2, in <module>
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 499, in exec_module
File "configfilereader.py", line 66, in <module>
File "configfilereader.py", line 40, in read_GoogleSheetNames
File "pandas\util\_decorators.py", line 211, in wrapper
File "pandas\util\_decorators.py", line 331, in wrapper
File "pandas\io\json\_json.py", line 757, in read_json
File "pandas\io\json\_json.py", line 915, in read
File "pandas\io\json\_json.py", line 937, in _get_object_parser
File "pandas\io\json\_json.py", line 1064, in parse
File "pandas\io\json\_json.py", line 1321, in _parse_no_numpy
ValueError: Expected object or value
The error comes from line
File "configfilereader.py", line 66, in <module>
File "configfilereader.py", line 40, in read_GoogleSheetNames
These are the functions which read csv file from exe file
def resource_path_output(fileName):
new_path00 = os.getcwd()
new_path0200 = new_path00[:-4]
new_path03xl00 = new_path0200 + fileName
return new_path03xl00
The line gives an error due to this line
f=read_GoogleSheetNames('output_file',resource_path_output('ConfigurationFile/OutputFile.csv'))
print(len(f),f)
def read_GoogleSheetNames(sheet_name,url):
df_csv_config=pd.read_json(resource_path_output(url))
I came to a conclusion that, pyinstaller
can have two functions while one will be for reading files from MEIPASS
folder which is temporary and the other one my function which erases from path last for letter which are for dist-folder
. I got resolved the issue by using a function resource_path_outpt
as a writer to output file(exporting) function and the other for reading purposes which as an answer I got from so
def resource_path_input(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
print(base_path)
print(os.path.normpath(os.path.join(base_path, relative_path)))
except Exception:
base_path = os.getcwd()
return os.path.normpath(os.path.join(base_path, relative_path))
But I have no clue how to combine these two functions within one, with try and except. You can see except but, that only is fine for running script as normal from python.