Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with conversion to exe
#1
Hello everyone,

I'm new to development. I tried coding a script that works perfectly fine using Python, but I need to convert it to an exe so that my other colleagues can use it.

When I attempt to convert it using "auto-py-to-exe," I encounter this error: "IndexError: tuple index out of range," and I'm struggling to resolve it.

Here's the code I'm using:

import tkinter as tk
from tkinter import filedialog
import pandas as pd

# Function to load and process the XLSX file
def process_xlsx():
    file_path = filedialog.askopenfilename(filetypes=[("XLSX files", "*.xlsx")])
    if file_path:
        df = pd.read_excel(file_path)

        # Replace null (NaN) values with an empty string in the "Description" column
        df['Description'] = df['Description'].fillna("")

        # List of words to filter out in the "Hostname" and "Description" columns
        words_to_remove_hostname = ["ALCATEL", "Galaxy", "EPW", "ETW", "EFW", "router", "HSRP", "8028"]
        words_to_remove_description = ["router", "HSRP", "Router", "WIDIS"]

        # Filter rows with keywords to remove in the "Hostname" and "Description" columns
        hostname_filter_condition = ~df['Hostname'].str.contains('|'.join(words_to_remove_hostname))
        description_filter_condition = ~df['Description'].str.contains('|'.join(words_to_remove_description))

        df = df[hostname_filter_condition & description_filter_condition]

        # Create a new "VLAN" column by extracting the VLAN number after the dot
        df['VLAN'] = df['Vlan'].str.split('.').str[-1]

        # Create a "Group" column with the first 5 characters of the hostname
        df['Group'] = df['Hostname'].str[:5]

        # Separate VLAN 1000 devices and others into two DataFrames
        df_vlan_1000 = df[df['VLAN'] == '1000'].copy()  # Using .copy()
        df_other = df[(df['VLAN'] != '1000') & (df['VLAN'] != '99')].copy()  # Exclude VLAN 1000 and 99

        # Remove the Vlan column which is no longer needed
        df_vlan_1000.drop(columns=['Vlan'], inplace=True)
        df_other.drop(columns=['Vlan'], inplace=True)

        # Sort the DataFrames by group and VLAN
        df_vlan_1000.sort_values(by=['Group', 'VLAN'], inplace=True)
        df_other.sort_values(by=['Group', 'VLAN'], inplace=True)

        # Write the DataFrames to an XLSX file with two sheets "VLAN_1000" and "Other"
        result_file_path = "Naming_Plan.xlsx"
        with pd.ExcelWriter(result_file_path) as writer:
            df_vlan_1000.to_excel(writer, sheet_name="VLAN_1000", index=False)
            df_other.to_excel(writer, sheet_name="Other", index=False)

        status_label.config(text="Data grouped by VLAN successfully.")

# Create the main window
root = tk.Tk()
root.title("Grouping Data by VLAN")

# Button to load and process the XLSX file
load_button = tk.Button(root, text="Load and Group by VLAN", command=process_xlsx)
load_button.pack(pady=20)

# Label to display status
status_label = tk.Label(root, text="")
status_label.pack()

# Start the main interface loop
root.mainloop()
Thank you for your help
Reply
#2
Create a new clean venv and install in your venv only auto-py-to-exe and the required dependencies of your program (pandas).

Some packages could cause trouble with PyInstaller.
The tool auto-py-exe uses PyInstaller.

python3 -m venv venv
source venv/bin/activate
pip install auto-py-to-exe pandas

auto-py-to-exe
On Windows you should use py.exe.

py -m venv venv
source venv/bin/activate
pip install auto-py-to-exe pandas

auto-py-to-exe
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#3
Thank you for your response. I tried creating a new virtual environment using your commands (I succeeded in this part thanks to your commands), but I still can't convert to an exe. I'm still getting the same error message "IndexError: tuple index out of range,"
Reply
#4
Try use Pyinstaller alone,also source venv/bin/activate dos not work on Windows.
# Make
G:\div_code
λ python -m venv pyinst_env

G:\div_code
λ cd pyinst_env\

G:\div_code\pyinst_env
λ G:\div_code\pyinst_env\Scripts\activate

# Install
(pyinst_env) G:\div_code\pyinst_env
λ pip install pyinstaller pandas openpyxl
Collecting pyinstaller .....

# Make with Pyinstaller
(pyinst_env) G:\div_code\pyinst_env
λ pyinstaller --onefile --noconsole py_tk.py
710 INFO: PyInstaller: 5.13.0
711 INFO: Python: 3.11.3
784 INFO: Platform: Windows-10-10.0.19045-SP0
785 INFO: wrote G:\div_code\pyinst_env\py_tk.spec
.....
So it work for me,i did also make so my test.xlsx(you could have postet a working one) did work and could make Naming_Plan.xlsx.
[Image: bpZqrN.png]
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020