8

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 Answers2

23

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

Sandeep
  • 246
  • 2
  • 3
  • 1
    Thank you. Saved my life. Just one question how would I find out something like this. I assumed something was wrong with version of pynput but how would I know which version to revert to is there a list supported versions? – Borut Flis Feb 13 '21 at 23:29
  • Saved my life too. I also wonder how one would figure this out though? – Ruben May 31 '21 at 09:35
  • @Ruben You can have a look to my answer for a fix. – May.D Jun 02 '21 at 11:12
  • Hi @May.D, Seems like that might work too, but for now running 1.6.8 worked just fine. I already have my .exe file running. – Ruben Jun 04 '21 at 07:44
7

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.

May.D
  • 1,832
  • 1
  • 18
  • 34