I have converted my script of '.py' to '.exe' using pyinstaller and auto-py-to-exe. Both can produce the '.exe' but there is some function where user need to select the files and chose which sheet they want to use. This sheet is not displayed after user select the excel files.
I already try import os but not working. Also, there is no error with the code I think because before conversion, the script works fine and i can see the sheet options after user selected the excel file but not after conversion. Do i need to add specific code or any materials for pyinstaller to read or find my user selection file? Here are some of my code as a reference:
def resource_path(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
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
def load_selected_sheet(dataframe_name, sheet_combobox):
global file_path
file_path = filedialog.askopenfilename(filetypes=[("Excel files", "*.xlsx *.xls")])
if file_path:
file_path = resource_path(file_path)
try:
excel_file = pd.ExcelFile(file_path)
sheet_names = excel_file.sheet_names
sheet_combobox["values"] = sheet_names
sheet_combobox.config(state="readonly") # Enable the ComboBox
print(f"File '{file_path}' selected.")
except Exception as e:
print(f"Error loading data: {str(e)}")
def save_selected_sheet(dataframe_name, selected_sheet_name):
global file_path
if selected_sheet_name:
try:
excel_file = pd.ExcelFile(file_path)
df = pd.read_excel(excel_file, sheet_name=selected_sheet_name)
globals()[dataframe_name] = df # Update the global DataFrame
print(f"Saved selected sheet to {dataframe_name}.")
#Display message
messagebox.showinfo("Success",f"Sheet saved to {dataframe_name} successfully.")
My question, is it because of the codes or packages from pyinstaller? I have run it using command prompt with '.py' format and it is working but not when converting it to '.exe'. Can you help me? NOTE: resource path is an addition function to fix this problem but not working. I don't have problem with the codes even without the resource part function, it works well.
This is due to the pyinstaller package. I have fixed this by using the following prompts:
pip uninstall pyinstaller
pip install --ignore-installed pyinstaller
.