PyInstaller: Single-file executable doesn't work - python

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/

Related

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

PYINSTALLER FAILED TO EXECUTE SCRIPT (used pynput)

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.

Py2exe NotImplementedError: resource_filename() only supported for .egg, not .zip

I am trying to convert a python file into an executable and for that I'm using py2exe. When running the setup.py script to generate the dist folder and the executable file everything goes well.
What goes wrong is that when I'm running the executable the following error message gets displayed:
Traceback (most recent call last):
File "q400.py", line 16, in <module>
File "SUAVE\__init__.pyc", line 12, in <module>
File "SUAVE\Plugins\__init__.pyc", line 11, in <module>
File "SUAVE\Plugins\load_plugin.pyc", line 37, in load_plugin
File "SUAVE\Plugins\pint\__init__.pyc", line 23, in <module>
File "SUAVE\Plugins\pint\unit.pyc", line 423, in __init__
File "pkg_resources\__init__.pyc", line 1171, in resource_filename
File "pkg_resources\__init__.pyc", line 1872, in get_resource_filename
NotImplementedError: resource_filename() only supported for .egg, not .zip
When I check the file unit.pyc at line 423 the code is:
data = pkg_resources.resource_filename(__name__, 'default_en.txt')
And when I check the library.zip in the dist folder there is no default_en.txt file, however, it is present in the site-packages module.
So is it because this file is a txt file that this error shows up?
I tried to force py2exe to import it but with no success.
Also I found a similar question here but the answer can't be applied in my case because I don't have any egg nor zip files implicated in the error (at least in my opinion).
Thank you

TypeError: expected str, bytes or os.PathLike object, not NoneType _ while using pyinstaller

I wrote 3 python scripts and all of them are working fine when I run them with python3.6. Now I wanted to build executable files for each of these scripts using pyinstaller. Please Note that I cannot install pyinstaller on the computer due to the rules in my institution, so I downloaded the pyinstaller package and run the pyinstaller.py with python3.6 from the directory and it works fine.
The problem which I'm facing right now is the following:
Building the .exe works for one script without problems, but if I try to build the other 2 scripts I get the following error :
Traceback (most recent call last):
File "pyinstaller.py", line 15, in <module>
run()
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/__main__.py", line 94, in run
run_build(pyi_config, spec_file, **vars(args))
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/build_main.py", line 791, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/build_main.py", line 737, in build
exec(text, spec_namespace)
File "<string>", line 22, in <module>
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/build_main.py", line 213, in __init__
self.__postinit__()
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/datastruct.py", line 161, in __postinit__
self.assemble()
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/build_main.py", line 472, in assemble
module_hook.post_graph()
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/imphook.py", line 414, in post_graph
self._process_hook_func()
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/building/imphook.py", line 433, in _process_hook_func
self._hook_module.hook(hook_api)
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/hooks/hook-_tkinter.py", line 245, in hook
hook_api.add_datas(_collect_tcl_tk_files(hook_api))
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/hooks/hook-_tkinter.py", line 208, in _collect_tcl_tk_files
tcl_root, tk_root = _find_tcl_tk(hook_api)
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/hooks/hook-_tkinter.py", line 159, in _find_tcl_tk
bins = selectImports(hook_api.__file__)
File "/home/akaroui/PyInstaller-3.3.1/PyInstaller/depend/bindepend.py", line 493, in selectImports
xtrapath = [os.path.dirname(pth)]
File "/usr/local/python/3.6.1/lib/python3.6/posixpath.py", line 154, in dirname
p = os.fspath(p)
TypeError: expected str, bytes or os.PathLike object, not NoneType
Does anyone have an idea how can I fix this problem ?
Here are more information :
Using Linux - Python3.6
the Scripts where I get the problem do open files and modify their content, and also run some pdflatex-scripts. They are as I mentioned working fine when I run them with Python, the only problem is building the .exe from them.

Going from pyqt designer to exe file

I just finished the first draft of a .ui file in the designer of pyqt, and I am wondering how I go from the .ui file to an exe to let someone test out my ui... I currently have a makefile that translates my .ui file into a .py file, but now I want to go from .py to .exe
Does anybody know how to do this? I have py2exe downloaded but not sure if this is what I want...
Please assume the people I want to test this don't have python downloaded and are using Windows (cross platform is better but windows will be used)
Thank you!
EDIT: when i run py2exe on my test.py (which was made from the test.ui)
I use
py -3.6 -m py2exe.build_exe test.py
and get
C:\Users\Chris\Desktop\makeExe>py -3.6 -m py2exe.build_exe test.py
Traceback (most recent call last):
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\runpy.py", lin
e 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\runpy.py", lin
e 85, in _run_code
exec(code, run_globals)
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\build_exe.py", line 145, in <module>
main()
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\build_exe.py", line 141, in main
builder.analyze()
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\runtime.py", line 160, in analyze
self.mf.import_hook(modname)
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\mf3.py", line 120, in import_hook
module = self._gcd_import(name)
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\mf3.py", line 274, in _gcd_import
return self._find_and_load(name)
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\mf3.py", line 357, in _find_and_load
self._scan_code(module.__code__, module)
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\mf3.py", line 388, in _scan_code
for what, args in self._scan_opcodes(code):
File "C:\Users\Chris\AppData\Local\Programs\Python\Python36\lib\site-packages\
py2exe\mf3.py", line 417, in _scan_opcodes
yield "store", (names[oparg],)
IndexError: tuple index out of range
C:\Users\Chris\Desktop\makeExe>
Py2exe didn't support signing whereas Pyinstaller has support for signing from version 1.4
So this is also a solution
pip install pyinstaller
pyinstaller --onefile --windowed test.py

Categories

Resources