我正在使用pyinstaller
为我的项目创建可执行文件,
我在名为 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())
命令(pyinstaller my_project.py
)运行顺利,我可以运行my_project.exe
,但是,我试图理解结构,但似乎找不到任何一个我的原始项目源代码或项目的字节码版本。我的理解是,这是包含的 python3.dll
将解析并执行我的项目的要求。
输出包含,
PyQt6
文件夹及其依赖项_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
我的问题是,我的原始代码(或字节码)在哪里执行?谢谢。
最佳答案
它位于 exe
文件中,但采用压缩形式 - 所以您不能只看它。要提取原始代码,请按照下列步骤操作:
运行 PyInstaller 的存档查看器(名为
pyi-archive_viewer
),以列出exe
文件的存档。这还将显示每个存档的起始点的位置。- 您可以在此处阅读有关已编译 python 文件的存档结构的更多信息:Inspecting Archives .
然后在出现提示时,提取(使用
x
)名称为主文件名称的存档。
以下是运行步骤 1 和 2 的方法(请参阅另一个示例 here ):
$ pyi-archive_viewer my_project.exe
--> here you'll get the archive names, including my_project.
--> you're now prompted to extract the content of any archive, so go ahead with:
? x my_project
--> you're now prompted to output the content to a new file.
-- go ahead with:
output filename? my_project.x
? q
- 您现在可以使用十六进制编辑器(例如 hxd )打开
my_project.x
(x
只是一个虚拟扩展)并查看原始文件的内容文件。
关于python - pyinstaller 将我的 Python 字节码放置在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76880841/