PYINSTALLER FAILED TO EXECUTE SCRIPT (used pynput) - python

Recently, I have installed pyinstaller 4.2.
This is the error I get after running the script from cmd:
Traceback (most recent call last):
File "Keylogger.py", line 1, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 359, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 359, in exec_module
File "pynput\keyboard\__init__.py", line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[41576] Failed to execute script Keylogger
The command I used to convert to .exe is "pyinstaller --onefile Keylogger.exe"
I am a beginner coder so I don't understand what the error actually is. Can anyone pls help me? Thank you.

Try running the below command.
pyinstaller --onefile Keylogger.py
Your python file ends with .py extension.

Related

PyInstaller: Single-file executable doesn't work

PS C:\Users\user> pyinstaller onefile Traceback (most recent call last): File "<frozen runpy>", line 198, in _run_module_as_main File "<frozen runpy>", line 88, in _run_code File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Scripts\pyinstaller.exe\__main__.py", line 7, in <module> File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\__main__.py", line 107, in run parser = generate_parser() ^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\__main__.py", line 78, in generate_parser import PyInstaller.building.build_main ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\building\build_main.py", line 35, in <module> from PyInstaller.depend import bindepend ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\depend\bindepend.py", line 26, in <module> from PyInstaller.depend import dylib, utils ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\depend\utils.py", line 33, in <module> from PyInstaller.depend import bytecode ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\depend\bytecode.py", line 95, in <module> _call_function_bytecode = bytecode_regex(rb""" ^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\depend\bytecode.py", line 60, in bytecode_regex pattern = re.sub( ^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\re.py", line 190, in sub return _compile(pattern, flags).sub(repl, string, count) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\depend\bytecode.py", line 62, in <lambda> lambda m: _instruction_to_regex(m[1].decode()), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\user\AppData\Local\Programs\Python\Python311-32\Lib\site-packages\PyInstaller\depend\bytecode.py", line 40, in _instruction_to_regex return re.escape(bytes([dis.opmap[x]])) ~~~~~~~~~^^^ KeyError: 'CALL_FUNCTION' I'm trying to create a single-file executable for Windows from a Python application, using pyinstaller, but the commend doesn't run and
I honestly do not know what that error is. All I can say is that
the command for making a single .exe file with pyinstaller is:
pyinstaller --onefile <filename>
For example pyinstaller --onefile myscript.py
I did a quick search and found this in pyinstaller: create one executable file
What you have done is pyinstaller onefile, which is the same as telling pyinstaller to create the executable using a file called onefile. When the program doesn't find the file 'onefile' it will not work, and it throws an error.
This was addressed here:
https://github.com/pyinstaller/pyinstaller/issues/6950
Looks like it's been merged in so make sure your PyInsaller version is 5.6 or greater.
I think you made a mistake when you writing arguments can you give more details? or if you can't use PyInsaller on shell you can use this library with pyinstaller gui https://pypi.org/project/auto-py-to-exe/

PyInstaller - when opening cant find _tkinter Module (required by PySimpleGui)

I have a quesetion. I made a Python App and wanted to distribute this to friends.
I used PySimpleGui for the GUI and when I open the .py App with Python it works fine. But when I package it with PyInstaller and then open it I get this message:
/Users/USERNAME/Documents/Dev/application/dist/APPLICATION  1 ✘  14:57:29 
Traceback (most recent call last):
File "stamp.py", line 5, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "PySimpleGUI/__init__.py", line 2, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "PySimpleGUI/PySimpleGUI.py", line 111, in <module>
File "PyInstaller/loader/pyimod03_importers.py", line 546, in exec_module
File "tkinter/__init__.py", line 37, in <module>
ModuleNotFoundError: No module named '_tkinter'
[53336] Failed to execute script 'APPLICATION' due to unhandled exception!
Im using MacOS with Big Sur 11.5, Python 3.9.6 (with Pyenv) and PyInstaller 4.5.1.
I already tried troubleshooting with:
Reinstalling PySimpleGui
Reinstalling tkinter
use "hidden imports" for both
...
but nothing works...
Can I bundle tkinter with the application?

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!
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

Can't transform a python program into exe

I want to transform a simple .py code into .exe using PyInstaller, the program works fine with python, but when I transform it into .exe using PyInstaller, it returns the error:
ModuleNotFoundError: No module named numpy.core._dtype.ctypes
I tried installing the ctypes module, but the same error happenened.
How can I fix this error?
.py code:
import numpy
input("Worked")
cmd output:
C:\Users\enzo\Desktop\Compilando\dist\iaf>iaf.exe
Traceback (most recent call last):
File "iaf.py", line 1, in <module>
File "c:\users\enzo\appdata\local\programs\python\python37\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\__init__.py", line 151, in <module>
File "c:\users\enzo\appdata\local\programs\python\python37\lib\site-packages\P
yInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "site-packages\numpy\ctypeslib.py", line 369, in <module>
File "site-packages\numpy\ctypeslib.py", line 358, in _get_typecodes
File "site-packages\numpy\ctypeslib.py", line 358, in <dictcomp>
ModuleNotFoundError: No module named 'numpy.core._dtype_ctypes'
[2872] Failed to execute script iaf
after I added to the beginning of the code:
import numpy.core._dtype_ctypes
my code works
spied on KmolYuan
As an alternative solution, you can downgrade your numpy package via
python -m pip install numpy==1.15.0
as there seems to be a problem for pyinstaller using the current numpy release (1.16.0).

How to fix the no dbm clone found error in pyinstaller

I have made a GUI app which uses subliminal in it . Then i tried compiling the program using PyInstaller . When i run the exe, it gives me the following error :-
Traceback (most recent call last):
File "main.py", line 375, in <module>
File "main.py", line 144, in __init__
File "site-packages\dogpile\cache\region.py", line 237, in configure
File "site-packages\dogpile\cache\backends\file.py", line 158, in __init__
File "site-packages\dogpile\cache\backends\file.py", line 182, in _init_dbm_file
File "dbm\__init__.py", line 75, in open
ImportError: no dbm clone found; tried ['dbm.gnu', 'dbm.ndbm', 'dbm.dumb']
Failed to execute script main
After this i tried explicitly importing dbm in my application as like :-
import dbm . But this also gives the same error.
Then I tried import dbm.gnu , dbm.ndbm , dbm.dumb .
This gives another error as shown below :-
Traceback (most recent call last):
File "main.py", line 3, in <module>
File "c:\program files\python35\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "userinterface.py", line 312, in <module>
File "c:\program files\python35\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "main.py", line 9, in <module>
File "c:\program files\python35\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module
exec(bytecode, module.__dict__)
File "dbm\ndbm.py", line 3, in <module>
ImportError: No module named '_dbm'
Failed to execute script main
Some googling and i found that it uses _dbm package from dbm.gdbm . so instead of import dbm.gnu , dbm.ndbm , dbm.dumb , I used import dbm.dumb .
Surprisingly, doing this started my application . But the subliminal doesn't find any subtitle now. So it's total useless now .
What i am doing wrong . whats the right way to fix this problem. while compiling , i have also tried giving --hidden-import dbm with no luck.
Here is the command that i use to compile using pyinstaller :-
pyinstaller main.py --hidden-import dbm --hidden-import dogpile.cache.backends.file --additional-hooks-dir=. --add-data guessit;guessit --add-data babelfish;babelfish -i vid2.ico -n Subtitler
I would be grateful for any clue or help :)
I found that , in _dbm package only works in UNIX like systems .
After some fiddling with it and finally fixed it .
In your main python file just use this import :-
import dbm.dump

Categories

Resources