Search code examples
pythonpyinstallerpython-module

Py to exe pyinstaller import errors


Im trying to convert a single file python script/project into an exe using pyinstaller

Even thought pyinstaller converts the script the .exe will run and throw this

Traceback (most recent call last):
File "main.py", line 4, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[16676] Failed to execute script main

I'm stumped , through my trial and erroring i figured that when i replace pynput with a module like random
the convertion works fine , but i need it to work with pynput
please help , thanks in advance!


Solution

  • Authors made some changes which i feel broke the reference.
    so instead of package it is referring file.

    - backend = backend(__package__)
    + backend = backend(__name__)
    

    pls try to downgrade your package and check that your app still works.

    pip install pynput==1.6.8
    

    then your command like following would work.

    pyinstaller --onefile   build_pkg_for.py