pythonpython-3.xpython-holidays

Python library Holidays doesn't work after compiling to exe


I created an application using the eel, pandas and holidays libraries. It retrieves the public holidays from my country and uses them to perform calculations for the report.

In the Pycharm interpreter, everything works as it should, the holidays are downloaded and the report is generated. After compiling the application to exe, when running the function responsible for generating the report, the error "no module named holidays.countries" is returned.

Code used to return holidays:

from datetime import datetime as dt
import holidays

holi = holidays.Poland(years=dt.today().year)

# I used this code -
# holidays.country_holidays('PL', years=dt.today().year) 
# - before, but with the same result

Console command used to compile application python -m eel main.py web --onefile --noconsole

More (maybe) useful informations:


Solution

  • I had similar problem with Tkinter. I was able to solve it with forced imports:

    --resource D:\...\venv\Library\bin\liblzma.dll --paths D:\...\venv\Library\bin --hidden-import tkinter.filedialog --hidden-import tkinter.messagebox --collect-all tkinter --hidden-import tkinter.messagebox
    

    Try to modify this command to your needs (I do not have such library so I cannot do it).

    Simply --paths should lead to folder where libs are stored in environment. This will be actually the same path as I have.

    --hidden-import is used to force import libraries for the build which are missing right now.

    --resource is used if you are missing any .dll (for example you encounter some exception after build with missing .dll)

    --collect-all should force pyinstaller to include all packages from lib but it does not work as it should.

    These are optional paratemers for pyinstaller.

    EDIT:

    Note that python is not optimized for .exe building and most likely will never be.