且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有 Pandas 的 PyInstaller 创建超过 500 MB 的 exe

更新时间:2023-12-01 23:16:16

PyInstaller 从 conda 包创建大可执行文件,从 pip 包创建小可执行文件.从这个简单的python代码:

PyInstaller create the big executable from the conda packages and the small executable from the pip packages. From this simple python code:

from pandas import DataFrame as df
print('h')

我通过 conda 包获得了 203MB 的可执行文件,通过 pip 包获得了 30MB 的可执行文件.但是 conda 是纯 virtualenv 的一个很好的替代品.我可以使用 conda 和 Jupyter 进行开发,创建一些 mycode.py(我可以将 jupyter notebook 作为 py 文件下载到 myfolder 中).但我的最终解决方案是下一个:如果没有,请安装 Miniconda 并从 Windows 开始菜单打开 Anaconda Prompt;

I obtain the 203MB executable by the conda packages and the 30MB executable by the pip packages. But conda is the nice replacement of the pure virtualenv. I can develop with conda and Jupyter, create some mycode.py (I can download jupyter notebook as py-file in myfolder). But my final solution is next: If you do not have it, install Miniconda and from the Windows Start Menu open Anaconda Prompt;

    cd myfolder
    conda create -n exe python=3
    activate exe
    pip install pandas pyinstaller pypiwin32
    echo hiddenimports = ['pandas._libs.tslibs.timedeltas'] > %CONDA_PREFIX%Libsite-packagesPyInstallerhookshook-pandas.py
    pyinstaller -F mycode.py

在我创建新环境exe"的地方,pypiwin32 需要 pyinstaller 但不会自动安装,hook-pandas.py 需要用 pandas 编译.此外,导入子模块并不能帮助我优化可执行文件的大小.所以我不需要这个东西:

Where I create new environment 'exe', pypiwin32 need for pyinstaller but is not installed automaticaly, hook-pandas.py need for compile with pandas. Also, import submodules do not help me optimize the size of the executable file. So I do not need this thing:

from pandas import DataFrame as df

但我可以使用通常的代码:

but I can just use the usual code:

import pandas as pd

此外,在路径中使用国家字母可能会出现一些错误,因此开发工具的英文用户帐户很好.

Also, some errors are possible along using the national letters in paths, so it is nice the english user account for development tools.