Python Error : No module named pkg_resources

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


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.


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