Search code examples
pythoninstallationexecutableimporterrorpy2exe

Import Error building an executable with py2exe


I program a software that connects with a mqtt broker and displays windows10 notifications using win10toaster among others. I wanted to create an executable with py2exe but when I run the .exe I get this output:


Traceback (most recent call last):
  File "suscribe.py", line 7, in <module>
  File "zipextimporter.pyc", line 168, in exec_module
  File "win10toast\__init__.pyc", line 15, in <module>
  File "zipextimporter.pyc", line 168, in exec_module
  File "pkg_resources\__init__.pyc", line 75, in <module>
  File "pkg_resources\extern\__init__.pyc", line 52, in create_module
  File "pkg_resources\extern\__init__.pyc", line 44, in load_module
ImportError: The 'packaging' package is required; normally this is bundled with this package so if you get this warning, consult the packager of your distribution.

my setup.py is the following:

from distutils.core import setup
import py2exe
from playsound import playsound 
import random
import time

from paho.mqtt import client as mqtt_client
from win10toast import ToastNotifier
packages = ['pkg_resources','win10toast','zipextimporter']
setup(
    name="Nombre ejecutable",
    version="1.0",
    description="Breve descripcion",
    author="autor",
    author_email="email del autor",
    url="url del proyecto",
    license="tipo de licencia",
    scripts=["suscribe.py"],
    console=["suscribe.py"],
    options={"py2exe": {"bundle_files": 1},
            'build_exe': {'packages':packages}
    },
    zipfile=None,
)
And this is my imports in the main .py:
from playsound import playsound 
import random
import time

from paho.mqtt import client as mqtt_client
from win10toast import ToastNotifier

I tried several things but I still get that Import - Error.

any ideas?

thanks in advance!


Solution

  • i can solve this problem.

    The solution came after that i include the following in my code:

    import packaging
    import packaging.version
    import packaging.specifiers
    import packaging.requirements
    

    Thanks!