1

I've started taking a multi-language course in meantime and now I'm practicing Python with beginner projects. I've made a small desktop notifier project and I want to make an .exe out of it. I use Anaconda3 and I write codes in Spyder4.

When I try to make an exe out of it, no matter what I try, it doesn't compile an .exe file, some error happens mid-compilation and it stops. Build folder and .spec file are okay, but dist folder remains empty.

Here's the code of the application I wrote:

import time
from win10toast import ToastNotifier

notTime = input("Enter the desired time of notification (HH:MM:SS, 24-hr): ")
notMsg = input("Enter your message: ")
while True:
    timeCur = time.strftime("%H:%M:%S")
    if timeCur == notTime:
        print(timeCur)
        break
    
notify = ToastNotifier()
notify.show_toast("Notification",notMsg)

The compile log shows two important errors, first one: Importing the numpy C-extensions failed. This error can happen for many reasons, often due to issues with your setup or how NumPy was installed.

We have compiled some common reasons and troubleshooting tips at:

https://numpy.org/devdocs/user/troubleshooting-importerror.html

Please note and check the following:

  • The Python version is: Python3.8 from "c:\users\kuzgu\anaconda3\python.exe"
  • The NumPy version is: "1.20.1"

and make sure that they are the versions you expect. Please carefully study the documentation linked above for further help.

Original error was: DLL load failed while importing _multiarray_umath

And the second one:

AssertionError: Failed to determine matplotlib's data directory!

To add some salt to the wound, PyInstaller itself actually works with more basic scripts that doesn't import anything, like the demos I've made during Python part of the course. The win10toast part makes the problem as I suppose, but I'm not sure.

How can I fix this problem?

1 Answers1

0

I use python 3.8 and Spyder 4.1.4

Program :

I modified your program :

import time
from win10toast import ToastNotifier
import six
import appdirs
import packaging.requirements

notTime = input("Enter the desired time of notification (HH:MM:SS, 24-hr): ")
notMsg = input("Enter your message: ")
while True:
    timeCur = time.strftime("%H:%M:%S")
    if timeCur == notTime:
        print(timeCur)
        break
    
notify = ToastNotifier()
notify.show_toast("Notification",notMsg,duration=10,icon_path="notif.ico")

I added three modules : six, appdirs, packaging.requirements. This modules help you to use your exe. I also added a duration of 10 secondes, i.e the the display time of the notification and an icon path. The icon should be in the same folder that your exe or your script.

Exe :

To create an exe, many solutions are availables :

  • pyinstaller
  • py2exe
  • auto-py-to-exe

You can use auto-py-to-exe because it's easy to handle to make an exe. The auto-py-to-exe App use the pyinstaller library and you can configure everything. It's a web application and you can see the pyinstaller command in a Current Command section.

When I created for the first time the exe, several errors were found, like you. During the creation of the exe, if the error comes from a module or a library, you can exclude it in the Advanced section with --exclude-module. I excluded PyQt5 library because this library create an issue.

Below, there is the pyinstaller command create by the auto-py-to-exe App :

pyinstaller --noconfirm --onedir --console --exclude-module "PyQt5" --add-data "C:/PATH/notif.ico;."  "C:/PATH/kuzgun_notif.py"

You need to add an icon to your notification. You shall add the icon file in the additionals files section.

You aren't the only person with this issue. I used this page, HERE, to help me.

pont_
  • 51
  • 7
  • 1
    Thank you so much, it really worked! However, my version of Spyder (and/or Python) swaps placement of duration and icon path in constructor. The program fully worked! Thank you again! – Kuzgun Wayne Aug 14 '21 at 12:15