Pyinstaller: Missing optional dependency 'openpyxl'

793 views
Skip to first unread message

Patricia Kappler

unread,
Nov 4, 2023, 11:46:29 AM11/4/23
to PyInstaller

Hello!

I want to make an executable file from my Python script (Python version 3.11.5, Anaconda) using Pyinstaller. The main function of the script is to access data from an excel file and provide this data in different files for other scripts. When I run the script in Spyder it works totally fine. However, if I use pyinstaller, the following error occurs:

ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl. [24544] Failed to execute script 'mwe' due to unhandled exception!


I want to make an executable file from my Python script (Python version 3.11.5, Anaconda) using Pyinstaller. The main function of the script is to access data from an excel file and provide this data in different files for other scripts. When I run the script in Spyder it works totally fine. However, if I use pyinstaller, the following error occurs:

ImportError: Missing optional dependency 'openpyxl'. Use pip or conda to install openpyxl. [24544] Failed to execute script 'mwe' due to unhandled exception!

I reinstalled openpyxl and also in Anaconda it is displayed as installed. I further created a new environment as recommended in some other posts about this problem. I tried pyinstaller --hidden-import openpyxl. Furthermore I tried pyinstaller --name=mwe --onefile mwe.py and then to add hiddenimports=[ 'openpyxl']' to the resulting mwe.spec file. But nothing worked so far.
The main function of my python script to access an excel file and print the data in a new txt file:

import pandas as pd

obs = (pd.read_excel('FINIFLUX.xlsx', usecols='F', header=2)).dropna()

np.savetxt('observation_points.txt', obs)


As I am pretty new to Python and especially to pyinstaller, I would be glad if somenone could help me!

Simon

unread,
Nov 28, 2023, 12:15:47 AM11/28/23
to PyInstaller
Hi Patricial,

I got the same problem too. And the attempts that I have tried based on the https://pyinstaller.org/en/stable/when-things-go-wrong.html do not work.

Have you figured out this error?

Many thanks.

Kind regards,
Simon
Reply all
Reply to author
Forward
0 new messages