带有Pandas的PyInstaller可以创建500 MB以上的exe [英] PyInstaller with Pandas creates over 500 MB exe

查看:135
本文介绍了带有Pandas的PyInstaller可以创建500 MB以上的exe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用PyInstaller 3.2.1创建exe文件,出于测试目的,我尝试为以下代码制作exe:

I try to create an exe file using PyInstaller 3.2.1, for test purpose I tried to make an exe for following code:

import pandas as pd
print('hello world')

经过相当长的时间(15分钟以上)后,我完成了620 MB的dist文件夹并构建了150 MB.我使用Python 3.5.2 | Anaconda自定义(64位)在Windows上工作.可能值得注意的是,在dist文件夹中,mkl文件负责将近300 MB. 我使用'pyinstaller.exe foo.py'运行pyinstaller.我尝试使用--exclude-module排除某些依赖项,但最终仍以巨大的文件结尾.我使用onefile还是onedir都没有任何区别.

After considerable amount of time (15mins +) I finished with dist folder as big as 620 MB and build - 150 MB. I work on Windows using Python 3.5.2 |Anaconda custom (64-bit). Might be worth noting that in dist folder mkl files are responsible for almost 300 MB. I run pyinstaller using 'pyinstaller.exe foo.py'. I tried using --exclude-module to exclude some dependencies, still ended up with huge files. Whether I use onefile or onedir doesn't make any difference.

我知道exe必须包含一些重要文件,但是正常大小可以达到1 GB是否正常?我可以在必要时提供警告日志,或者提供任何有助于解决此问题的方法.

I am aware that exe must contain some important files but is it normal to be as big as almost 1 GB? I can provide warning log if necessary or anything that could be helpful to solve the matter.

P.S.同时,我的同事使用相同的示例脚本创建了一个exe文件,最终结果不到100 MB,不同之处在于他没有使用anaconda.可能是这样吗?

P.S. In parallel my coworker created an exe from same sample script and ended up with less than 100 MB, difference is he is not using anaconda. Could that be the matter?

任何帮助将不胜感激.

推荐答案

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(我可以在myfolder中将pypy文件下载为pypy文件).但是接下来是我的最终解决方案: 如果没有安装,请安装 Miniconda ,然后从Windows开始"菜单中打开Anaconda提示符;

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%\Lib\site-packages\PyInstaller\hooks\hook-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.

这篇关于带有Pandas的PyInstaller可以创建500 MB以上的exe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆