Python Error : No module named pkg_resources

21,433

Solution 1

This is caused because of a broken setuptools package, you just need to reinstall it.

For most operating systems: pip install setuptools

Linux: apt-get install python-setuptools or yum install python-setuptools

Solution 2

pyinstaller 3.6 is incompatible with setuptools 45.1.0 on python 3.7.*, should be downgraded to 45.0.0

pip install setuptools==45.0.0

can also be fixed with passing/adding hidden_imports 'pkg_resources.py2_warn' to pyinstaller spec

Issue and solutions are tracked here: https://github.com/pypa/setuptools/issues/1963

Solution 3

I found solution from here.

  1. In my case, I open hook-pkg_resources.py file from the following directory:

    ~/.local/lib/python3.6/site-packages/PyInstaller/hooks/
    
  2. After that I added this line of code:

    hiddenimports.append('pkg_resources.py2_warn')
    

    between these two lines of code:

    hiddenimports = collect_submodules('pkg_resources._vendor')
    

    and

    excludedimports = ['__main__']
    
  3. After that, I ran PyInstaller again and the resulted executable worked like charm.

Solution 4

Stumbled uppon this answer first on google when searching for this error code, so for future reference ill just leave a link to this issue that solved my problem:

https://stackoverflow.com/a/59979390/10565375

tldr:

pyinstaller --hidden-import=pkg_resources.py2_warn example.py
Share:
21,433
Solenne Daguerre
Author by

Solenne Daguerre

Updated on August 05, 2022

Comments

  • Solenne Daguerre
    Solenne Daguerre over 1 year

    I would like to use Python3.7 on MacOS

    I already Python 2.7 version.

    I created an alias on .bash_profile, alias python="/usr/local/bin/python3.7" then source ~/.bash_profile.

    So I deleted Python2.7 to /usr/local/lib/

    Now, when I try to execute pip install PySide2, I have an error :

    Traceback (most recent call last):
      File "/usr/local/bin/pip", line 6, in <module>
        from pkg_resources import load_entry_point
    ImportError: No module named pkg_resources
    

    I think this error has happened since I deleted Python2.7

    Someone can help me to resolve my error ?

    Thank you !