Cheang Wai Bin
Cheang Wai Bin

Reputation: 143

Pyinstaller Failed to execute script pyi_rth_pkgres

I converted the py script to exe using pyinstaller but when I try to run the exe I got this. How can I fix it? Error image

Upvotes: 2

Views: 5016

Answers (2)

Cheang Wai Bin
Cheang Wai Bin

Reputation: 143

Answer provided by Sebastian which is passing the module to hidden import do solve the problem too. I happen to found another solution while waiting for the answers, just have to reinstall pyinstaller which I pip install pyinstaller initially

To uninstall the pyinstaller:

pip uninstall pyinstaller

To install pyinstaller again:

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

Upvotes: 0

You have to tell pyinstaller what modules it need to bundle in the program, so, in your case, you have to pass as hidden import this: pkg_resources

In the .spec file that generated after running the pyinstaller, you will find an option like this:

hiddenimports=[]

Put it like this:

hiddenimports=["pkg_resources"]

Then, run pyinstaller like this:

pyinstaller app.spec

Or, if you still want to run it trought the .py, pass it as parameter like

pyinstaller app.py --hidden-import pkg_resources

Normally, if your program its more than a "Hello world", this is going to be a few more modules, you just need to add them all to hiddenimports as a list until there is no more ModuleNotFoundError.

Remember to NOT run pyinstaller to the .py file if you modified the .spec file, as it will create a new one and overwrite it, ignoring the previous.

You have to execute pyinstaller with the .spec file

Upvotes: 6

Related Questions