8
votes

A friend of mine asked me to write him a program, and I used pynput to handle some of the inputs and other features. When I convert the program an executable with pyinstaller, launcing the executable gives me this error: File "site-packages\pynput\keyboard\__init__.py", line 31, in <module> File "site-packages\pynput\_util\__init__.py", line 82, in backend ImportError [11492] Failed to execute script friend_project

I have tried using the pyinstaller command pyinstaller --onefile friend_project.py, and also using auto-py-to-exe to run it.

Using pyinstaller with other modules like pygame or pyopengl gives me no error, but this one module does. Running the script by it self with the python inturpeter works fine, but I would perfer to have it be an exe so I can give it to him with out him needing python to run it.

2
Have you tried hidden imports when building the exe? - SajanGohil
@SajanGohil Yes, but I will try it again to see if it works. - user13140483
I could use pynput with pyinstaller to pack my py file in the past. - jizhihaoSAMA
@jizhihaoSAMA was there a specific way you typed the command? If not I might have a problem with the version of pynput I am using... - user13140483
Just pyinstaller -F x.py.The same as yours. - jizhihaoSAMA

2 Answers

23
votes

Please fall back to 1.6.8 version of pynput. pip install pynput==1.6.8

2
votes

If you are running Windows you need to add these parameters to the command line (for the first time, after that they will be included in the generated spec file).

--hidden-import "pynput.keyboard._win32" --hidden-import "pynput.mouse._win32"

For Linux, use:

--hidden-import "pynput.keyboard._xorg" --hidden-import "pynput.mouse._xorg"

More information can be found in this Github issue.