Python 脚本 .exe 比 .py 慢

Python script slower as .exe than as .py

我正在 Python 中编写一个应用程序,其中使用 PySide 作为 GUI,还使用 ​​modbus_tk 用于我的 PC 和其他设备之间的 Modbus 通信嵌入式控制器。

我注意到 当我使用 py2exe[=22 将我的脚本字节编译为 Windows 应用程序 (.exe) 时=], 请求发送到控制器的速度比 Python 脚本 (.py) 慢

你有过这样的经历吗?正常吗?我应该怎么做才能加快我的程序?任何帮助都将受到高度重视。

来自https://en.wikipedia.org/wiki/Py2exe

Although this program transforms a .py file to an .exe, it does not make it run faster as py2exe just bundles the Python bytecode rather than converting it to machine-code. It may even run slower than using the Python interpreter directly because of startup overhead.

您无法编译(标准)Python 代码。