ModuleNotFoundError: No module named 'pkg_resources.py2_warn'

1,208 views
Skip to first unread message

ttepperg

unread,
Apr 21, 2020, 3:58:11 AM4/21/20
to PyInstaller
Hi Guys,

I just updated my python 3.6 version to a more recent one, and suddenly I get the error:

ModuleNotFoundError: No module named 'pkg_resources.py2_warn'

when running a Mac App.

From what I could find. apparently the problem is related to the version of
setuptools (was 45 before, is 46 now). According to the discussion here:


A workaround is to compile the code with the flag:

hidden-import='pkg_resources.py2_warn'

And it actually works. However, I find this to be just an ugly solution and I was wondering
whether there is another way to solve this problem?

Cheers,

Thor.

bwoodsend

unread,
Apr 21, 2020, 8:23:48 AM4/21/20
to PyInstaller
There are a couple of others.

One is to put the following somewhere in your code:
import pkg_resources.py2_warn
Or to make it work as well with older setuptools versions:
try:
   
import pkg_resources.py2_warn
except ImportError:
   
pass

A more satisfactory solution would be to use PyInstaller's hooks which tell PyInstaller contain the hidden-import='pkg_resources.py2_warn' information. The hook for pkg_resources has been updated on github but the changes haven't been released yet. You could upgrade to the developer version on Github or you could manually update that file in your own installation.

Alternatively you can download that hook file and put it somewhere PyInstaller can find it (usually next to your main script).

Brénainn

Thorsten Tepper García

unread,
Apr 22, 2020, 3:23:06 AM4/22/20
to pyins...@googlegroups.com
Hi Brénainn,

Thanks a lot, that helps!

Thor.

-----------------------------------------------
Dr. Thorsten Tepper García
Astrophysicist
www.thorsten.mx
> --
> You received this message because you are subscribed to the Google Groups "PyInstaller" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pyinstaller...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pyinstaller/39fde230-b31e-4c7b-ad56-0509da6dbca5%40googlegroups.com.

ankit kumar

unread,
May 13, 2020, 5:32:43 AM5/13/20
to PyInstaller
Hi,
I am getting No module named 'pkg_resources.py2_warn' in pyinstaller when running the exe.
Things that I have tried:
                                   1. Updating the setuptools and pyinstaller (although I am already having the latest ones).
                                   2. Used try except block with pass to ignore exceptions in pyi_rth_pkgres.py and pyimod03_importers.py by taking the reference from one of the post from this forum.
                                   
What I assume is that if I comment out the import statement of dialogflow_v2 in my script it works fine otherwise if I run the exe with dialogflow_v2 import statement, I get below error:

                                                                                File "site-packages\PyInstaller\loader\rthooks\pyi_rth_pkgres.py", line 13, in <module>
                                                                                File "c:\users\ankit.bw.kumar\.conda\envs\envforpyqt\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 623, in exec_module
                                                                                exec(bytecode, module.__dict__)
                                                                                File "pkg_resources\__init__.py", line 86, in <module>
                                                                                ModuleNotFoundError: No module named 'pkg_resources.py2_warn'
                                                                                [17696] Failed to execute script pyi_rth_pkgres.

bwoodsend

unread,
May 13, 2020, 8:34:31 AM5/13/20
to PyInstaller
Now don't take this the wrong way but we've answered this question more times than I can count including on this very conversation. Are these not findable on Google? Are none of them understandable? Do none of them work for you?

Reply all
Reply to author
Forward
0 new messages