I am trying to create an executable from two python scripts. One script defines the GUI for the other backend script. The backend is reading in excel files, creating DataFrames with them for manipulation, then outputting a new excel file. This is the code that reads in the excel file, where "user_path, userAN, userRev1, userRev2" are grabbed as user input from the GUI:
import pandas as pd
import numpy as np
import string
from tkinter import messagebox
import os
def generate_BOM(user_path, userAN, userRev1, userRev2):
## Append filepath with '/' if it does not include directory separator
if not (user_path.endswith('/') or user_path.endswith('\\')):
user_path = user_path + '/'
## Set filepath to current directory if user inputted path does not exist
if not os.path.exists(user_path):
user_path = '.'
fileFormat1 = userAN + '_' + userRev1 + '.xls'
fileFormat2 = userAN + '_' + userRev2 + '.xls'
for file in os.listdir(path=user_path):
if file.endswith(fileFormat1):
df1 = pd.read_excel(user_path+file, index_col=None)
if file.endswith(fileFormat2):
df2 = pd.read_excel(user_path+file, index_col=None)
When running the two scripts through Spyder, everything works perfectly. To create the exe, I am using Pyinstaller with the following command:
pyinstaller --onefile Delta_BOM_Creator.py
This results in the following error:
Traceback (most recent call last):
File "c:\users\davhar\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\users\davhar\anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\davhar\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 7, in <module>
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 737, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 684, in build
exec(code, spec_namespace)
File "C:\Users\davhar\.spyder-py3\DELTA_BOM_Creator\Delta_BOM_Creator.spec", line 7, in <module>
a = Analysis(['Delta_BOM_Creator.py'],
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 242, in __init__
self.__postinit__()
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 160, in __postinit__
self.assemble()
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 414, in assemble
priority_scripts.append(self.graph.run_script(script))
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\depend\analysis.py", line 303, in run_script
self._top_script_node = super(PyiModuleGraph, self).run_script(
File "c:\users\davhar\anaconda3\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1411, in run_script
contents = fp.read() + '\n'
File "c:\users\davhar\anaconda3\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x93 in position 3965: invalid start byte
I've tried everything I could find that somewhat related to this issue. To list just a few:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 15: invalid start byte
https://www.dlology.com/blog/solution-pyinstaller-unicodedecodeerror-utf-8-codec-cant-decode-byte/
Pandas read _excel: 'utf-8' codec can't decode byte 0xa8 in position 14: invalid start byte
I've never used Pyinstaller, or created an executable from python at all, so apologies for being a big time noob.
SOLUTION: I found a solution. I went into the codecs.py file mentioned in the error and added 'ignore' to line 322
(result, consumed) = self.buffer_decode(data, 'ignore', final)