I tried to convert my data analyst project to GUI using Tkinter library. I build the entire project on PyCharm and everything worked.
so I tried to convert my project to exe.
on the terimal I typed this code:
pyinstaller.exe --onefile --icon="icon.png" gui.py
And on the dist folder, I copy my asset folder to the new folder with the exe (so all the images can work, and they did - my exe project work) all the graph display works. Here is my dist folder:
although when I try to execute my DataFrame to excel project I got an error on the terminal of the exe project:
Exception in Tkinter callback
Traceback (most recent call last):
File "tkinter\__init__.py", line 1921, in __call__
File "gui.py", line 180, in <lambda>
File "Analyst.py", line 64, in print_sum
File "Analyst.py", line 10, in download_df_to_csv_local
File "pandas\core\generic.py", line 2345, in to_excel
File "pandas\io\formats\excel.py", line 888, in write
File "pandas\io\excel\_openpyxl.py", line 49, in __init__
ModuleNotFoundError: No module named 'openpyxl'`
As you can see the problem was on my file Analyst.py on the function:
def download_df_to_csv_local(df):
token_id = secrets.token_urlsafe(6)
df.to_excel(r'C:\Users\עידן\Desktop\all_connected' token_id '.xlsx', index=False)
I have to mention that everything worked on my PyCharm, only when I compiled to exe I got errors
CodePudding user response:
This error happens when there is an import that is not visible or directly imported in the main file which is being converted to exe. As pandas uses the module openpyxl to read and write to different excel formats.
You can use the --hidden-import MODULE-NAME
option in pyinstaller.
The command will look like this:
pyinstaller --onefile --hidden-import openpyxl --icon="icon.png" gui.py
CodePudding user response:
I solve my own error by follow this way:
- On the terminal make sure that you are on the on the project path.
- Type
pip install openpyxl
- Execute the file to exe by type
pyinstaller --onefile --icon="icon.png" gui.py