如何使用pyinstaller创建最小大小的可执行文件? [英] How can I create the minimum size executable with pyinstaller?

查看:379
本文介绍了如何使用pyinstaller创建最小大小的可执行文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10上,已经安装了anaconda,但我想使用python 3.5在新的,干净的最小环境中独立创建可执行文件.所以我做了一些测试:

I am on Windows 10, I have anaconda installed but I want to create an executable independently in a new, clean minimal environment using python 3.5. So I did some tests:

TEST1: 我在文件夹testenv中仅创建了一个python脚本test1.py:

TEST1: I created a python script test1.py in the folder testenv with only:

print('Hello World')

然后我创建了环境,安装了pyinstaller并创建了可执行文件

Then I created the environment, installed pyinstaller and created the executable

D:\testenv> python -m venv venv_test
...
D:\testenv\venv_test\Scripts>activate.bat
...
(venv_test) D:\testenv>pip install pyinstaller
(venv_test) D:\testenv>pyinstaller --clean -F test1.py

它创建了大约6 Mb的我的test1.exe

And it creates my test1.exe of about 6 Mb

测试2:我将test1.py修改如下:

TEST 2: I modified test1.py as follows:

import pandas as pd
print('Hello World')  

我在环境中安装了熊猫,并创建了新的可执行文件:

I installed pandas in the environment and created the new executable:

(venv_test) D:\testenv>pip install pandas
(venv_test) D:\testenv>pyinstaller --clean -F test1.py

它会创建我的test1.exe,现在它的大小为 230 Mb !!!

Ant it creates my test1.exe which is now of 230 Mb!!!

如果我运行命令

(venv_test) D:\testenv>python -V
Python 3.5.2 :: Anaconda custom (64-bit)

当我运行pyinstaller时,收到一些我不理解的消息,例如:

when I am running pyinstaller I get some messages I do not understand, for example:

INFO: site: retargeting to fake-dir 'c:\\users\\username\\appdata\\local\\continuum\\anaconda3\\lib\\site-packages\\PyInstaller\\fake-modules'

我也收到有关matplotlib和其他与我的代码无关的模块的消息,例如:

Also I am getting messages about matplotlib and other modules that have nothing to do with my code, for example:

INFO:   Matplotlib backend "pdf": added
INFO:   Matplotlib backend "pgf": added
INFO:   Matplotlib backend "ps": added
INFO:   Matplotlib backend "svg": added

我知道有一些相关的问题: 减小pyinstaller exe的大小

I know there are some related questions: Reducing size of pyinstaller exe, size of executable using pyinstaller and numpy but I could not solve the problem and I am afraid I am doing something wrong with respect to anaconda.

所以我的问题是: 我究竟做错了什么?我可以减小可执行文件的大小吗?

So my questions are: what am I doing wrong? can I reduce the size of my executable?

推荐答案

问题是您不应该使用虚拟环境,尤其是anaconda.请下载默认的python 32位,并仅使用必要的模块.然后按照链接中提供的步骤操作,这肯定可以解决它.

The problem is that you should not be using a virtual environment and especially not anaconda. Please download default python 32 bit and use only necessary modules. Then follow the steps provided in the links, this should definitely fix it.

尽管您创建了一个虚拟环境,但是您确定您的spec文件没有链接到旧的Anaconda条目吗?

Although you created a virtual env, are you sure your spec file is not linking to old Anaconda entries?

如果所有操作均失败,则提交错误,因为这很奇怪.

If all this fails, then submit a bug as this is very strange.

这篇关于如何使用pyinstaller创建最小大小的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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