I am using pyinstaller
to create an executable for my project,
I am using the following code in a file called my_project.py
,
import sys
from PyQt6.QtWidgets import QApplication, QFrame, QVBoxLayout, QPushButton
from PyQt6.QtCore import QEvent, QObject
class ChildWidgetEventFilter(QObject):
def eventFilter(self, obj: 'QObject', event: 'QEvent') -> bool:
if event.type() == QEvent.Type.MouseButtonPress:
print("ChildWidgetEventFilter: eventFilter")
return False
return super().eventFilter(obj, event)
class ChildWidget(QPushButton):
def __init__(self, *args):
super().__init__(*args)
"""
We need to set our event filter to a variable or it will be garbage collected when we leave
scope, i.e. self.installEventFilter(ChildWidgetEventFilter()) will not work.
"""
self._event_filter = ChildWidgetEventFilter()
self.installEventFilter(self._event_filter)
def event(self, event: QEvent) -> bool:
if event.type() == QEvent.Type.MouseButtonPress:
print("ChildWidget: event")
return False
return super().event(event)
def mousePressEvent(self, event):
print("ChildWidget: mousePressEvent")
class ParentWidget(QFrame):
def mousePressEvent(self, event) -> None:
print("Inside ParentWidget mousePressEvent")
app = QApplication(sys.argv)
main_window = ParentWidget()
layout = QVBoxLayout()
layout.addWidget(ChildWidget("Click me! I'm the child widget"))
main_window.setLayout(layout)
main_window.show()
sys.exit(app.exec())
The command (pyinstaller my_project.py
) runs smoothly and I can run my_project.exe
, however, I am trying to understand the structure and cannot seem to find either my original project source code or bytecode version of my project. My understanding is that this is a requirement which the included python3.dll
will parse and execute my project.
The output contains,
PyQt6
Folder and its dependencies_bz2.pyd
_decimal.pyd
_hashlib.pyd
_lzma.pyd
_socket.pyd
_ssl.pyd
base_library.zip
libcrypto-1_1.dll
libssl-1_1.dll
my_project.exe
python3.dll
python310.dll
select.pyd
unicodedata.pyd
VCRUNTIME140.dll
VCRUNTIME140_1.dll
My question is, where is my original code (or the bytecode) at for it to execute? Thanks.
PyInstaller embeds compiled Python code (.pyc
files) within the executable (my_project.exe
), but not the original source (.py
). The embedded .pyc
files can be extracted from the executable using a tool like PyInstaller Extractor.