I want to freeze a Python application that has, as one of its features, the ability to produce freezed Python applications using PyInstaller. Here is a minimal application showing what I want to achieve:
import PyInstaller.__main__
with open('inception', 'w', encoding='utf-8') as f:
f.write('import sys; print("Hello from the inside")\n')
PyInstaller.__main__.run(['--noconfirm', '--onedir', 'inception'])
Freezing this with PyInstaller
PS> pyinstaller --noconfirm --onedir example.py
should produce an executable exemple.exe
that can be executed to produce inception.exe
.
On the first try, I got the following error
PS> .\dist\example\example.exe
PyInstaller cannot check for assembly dependencies.
Please install pywin32-ctypes.
pip install pywin32-ctypes
This was fixed by installing pywin32
(pywin32-ctypes
was already installed) and changing PyInstaller's compat.py
file as explained here. Rebundling the application now results in the following error
PS> .\dist\example\example.exe
Traceback (most recent call last):
File "example.py", line 2, in <module>
import PyInstaller.__main__
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "d:\code\stackoverflow\pyinstaller_inception\venv\lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 627, in exec_module
exec(bytecode, module.__dict__)
File "lib\site-packages\PyInstaller\__init__.py", line 66, in <module>
File "lib\site-packages\pkg_resources\__init__.py", line 481, in get_distribution
File "lib\site-packages\pkg_resources\__init__.py", line 357, in get_provider
File "lib\site-packages\pkg_resources\__init__.py", line 900, in require
File "lib\site-packages\pkg_resources\__init__.py", line 786, in resolve
pkg_resources.DistributionNotFound: The 'PyInstaller' distribution was not found and is required by the application
[14376] Failed to execute script example
So it seems like PyInstaller does not bundle itself inside the application. There is an issue on PyInstaller github page, but it does not really help. Is this even possible? If so, how?
This needs to run on Windows 10, with Python 3.7. I am using PyInstaller version 3.5.
from How to include PyInstaller inside a PyInstaller bundle?
No comments:
Post a Comment