Reputation: 1
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!
Upvotes: 0
Views: 294
Reputation: 1
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!
Upvotes: 0
Reputation: 1
The package 'pkg_resources' is loading the package 'packaging' dinamically instead of a Import statement. You can check this from the last line at the github repository https://github.com/pypa/setuptools/blob/main/pkg_resources/extern/__init__.py In fact, they are installing the package if it is not included, but in the case of py2exe environment, it is not possible, therefore, an error is raised.
You can solve this by putting 'packaging' in your setup.py packages list Maybe you will need to repeat the step if any more package is missing
Upvotes: 0