Search code examples
pythonpyinstaller

Pyinstaller refuses to include win10toast library


I'm trying to make a simple alert exe

import win10toast

toaster = win10toast.ToastNotifier()
toaster.show_toast("Title", "Testing alert")

using pyinstaller with the bat file as below:

@echo off

cd /d "D:\General Software\PycharmProjects\Project1\venv\Scripts"

call activate.bat

cd /d "%~dp0"

pyinstaller --onefile alert_test.py

pause

But it seems like pyinstaller just doesn't include win10toast, when I run the program I will get this error: pkg_resources.DistributionNotFound: The 'win10toast' distribution was not found and is required by the application. Even when I use --hidden-import win10toast it still doesn't work.

I know that I can use onedir then manually copy the library but I want to know what is the problem here. Does anyone know why?


Solution

  • the short explanation is that pyinstaller isn't actually a compiler that turns python code into machine code (a .exe file), it actually just gathers the python code and then gives it an entry point. which is why some modules like win10toast don't work with it out of the box.

    the longer, and probably more wrong explanation is this:

    a normal compiler just reads the code, turns it into something called IR and then compiles the code into a programming language for you computer, aka machine code. meanwhile, pyinstaller looks through your project, gathers all files it finds as necessary, places them in a single folder, it then gathers all that python code and makes an entry point using an executable (to any more experienced programmer, i know this isn't how this works, but this is easier to explain this way). because of this, sometimes it misses some modules that don't import in a regular way or work in a different way then usual. for example, PyQt, which is (basically) just a c++ program compiled into python, has a ton of issues the pyinstaller community had to solve in order for pyqt to work. an example for something they haven't worked on yet would be win10toast, which is very OS specific and seems to be located in a different place then the normal VENV placement.