Solution to Pyinstaller Problem – Failed to execute script pyi_rth_pkgres

Failed to execute script pyi_rth_pkgres is an error which happens when you install pyinstaller using pip.

In this article I am going to explain what happens when you get this error and how you can solve it with a main solution, we will also explore other solutions which can possibly solve the issue.

Explaining the Error : Failed to execute script pyi_rth_pkgres

This error occurs when you install pyinstaller using pip like in the example bellow

                                                                       #
pip install pyinstaller
                                                                       #

The error message should look like the error in the example bellow, make sure you have the same error message in order to avoid confusion.

                                                                       #
line 389, in load_module exec(bytecode, module.dict) File "site-packages\setuptools-
20.7.0-py3.5.egg\pkg_resources__init__.py", line 68, in File
 "site-packages\setuptools-20.7.0-py3.5.egg\pkg_resources\extern__init__.py", line 60,
 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. Failed to execute script pyi_rth_pkgres
                                                                       #

Bellow I make my best attempt at solving the error and present multiple possible solutions.

Solution 1 : uninstall pyinstaller then correctly install it

The solution is simple, try to remove your pyinstaller installation first. You can do that by using pip uninstall.

                                                                       #
pip uninstall pyinstaller
                                                                       #

Then you should install from the following link.

                                                                       #
https://github.com/pyinstaller/pyinstaller/archive/develop.zip
                                                                       #

Using the command bellow.

                                                                       #
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
                                                                       #

This solution should work like a charm. If you are unlucky skip to the final solution.

Solution 2 : use –hidden-import.

The second solution is to use –hidden-import

You can add that argument to the command and use it as follows.

                                                                       #
pyinstaller --hidden-import=pkg_resources.py2_warn example.py
                                                                       #

I hope this solution has been helpful.

If this article has been useful for your particular case, consider donating to our Kofi account, there is a red button at the top of this page.

Summing-up

This is the end of the article, the error could be confusing but with a little bit of investigating the error could be solved, thanks for reading our post and good luck with the scripts to come.

If you want to support us consider donating to our Kofi account using the red button on top of this page. Keep coding, keep learning Python and cheers.

If you want to learn more about Python, please check out the Python Documentation : https://docs.python.org/3/