no module named pkg_resources.py2_warn pyinstaller

Use PyInstaller --hidden-import=pkg_resources.py2_warn my_script.py to fix this. Same applies to most ModuleNotFoundErrors.

That hidden module was added in setuptools version 45.0.0 and removed in 49.0.0 so either downgrading below or upgrading above will also fix it.

Please do not fix this by putting import pkg_resources.py2_warn at the top of your code as others have done as this will obviously break if you change your setuptools version to be outside the above range.

This issue will be fixed permanently in version 4.0 of PyInstaller once we eventually get round to releasing it.


As of 7/16/2020, upgrading setuptools now resolves this error. Downgrading setuptools like the other answers prescribe is not necessary anymore. See this discussion

On Win10, upgrade with

pip3 install setuptools --upgrade

However as Vikramaditya said, downgrading below ver 45.0.0 works too.