很大的贡献可能要归功于 Qt(由matplotlib
) and MKL(由numpy
).
参见示例:
- 使用 pyinstaller 减小 pyqt5 html-viewer 应用程序构建的大小
-
使用 pyinstaller 和 numpy 的可执行文件的大小.
Using OpenBlas而不是 MKL 可以提供帮助。
为了说明差异,我构建了一个简单的示例应用程序matplotlib/Qt
and numpy
使用两个不同的conda环境,在Windows10:一个使用 MKL,另一个使用 openblas,如下面的 YAML 文件中所指定。
生成的可执行文件大小为:
- mkl: 312 MB
- openblas: 100 MB
可以使用以下命令创建环境conda env create -f <filename>
.
MKL 环境(另请参阅这次讨论):
name: mkl
dependencies:
- python=3.8
- matplotlib
- pyinstaller
Openblas环境(基于this and this):
name: openblas
dependencies:
- python=3.8
- conda-forge::blas=*=openblas
- conda-forge::matplotlib
- pyinstaller
应用示例:
from matplotlib import pyplot as plt
import numpy as np
if __name__ == '__main__':
x = np.arange(0, 10 * np.pi, 0.1)
y = np.sin(x)
dot_product = np.dot(y, y.T) # just some matrix operation
plt.plot(x, y)
plt.title(dot_product)
plt.show()
构建使用:pyinstaller --clean -w -F main.py