How to include only needed modules in pyinstaller?(如何在pyinstaller中只包含需要的模块?)
本文介绍了如何在pyinstaller中只包含需要的模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用pyinstaller
为我的单个python文件生成.exe
文件,但是文件大小超过30MB,启动非常慢。从我收集到的信息来看,pyinstaller
默认情况下捆绑了很多不需要的东西。有没有一种方法可以确保pyinstaller
找出只需要什么并只捆绑它们?我的脚本上的导入部分如下所示:
import datetime
import os
import numpy as np
import pandas as pd
import xlsxwriter
from tkinter import *
编辑:
或者有没有办法查看它捆绑的所有模块的列表?这样我就可以检查它们并排除我不需要的那些。
推荐答案
我最终使用了cx_Freeze
。它似乎比py2exe
或pyinstaller
工作得好得多。我编写的setup.py
文件如下所示:
import os
import shutil
import sys
from cx_Freeze import setup, Executable
os.environ['TCL_LIBRARY'] = r'C:inPython37-32 cl cl8.6'
os.environ['TK_LIBRARY'] = r'C:inPython37-32 cl k8.6'
__version__ = '1.0.0'
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
include_files = ['am.png']
includes = ['tkinter']
excludes = ['matplotlib', 'sqlite3']
packages = ['numpy', 'pandas', 'xlsxwriter']
setup(
name='TestApp',
description='Test App',
version=__version__,
executables=[Executable('test.py', base=base)],
options = {'build_exe': {
'packages': packages,
'includes': includes,
'include_files': include_files,
'include_msvcr': True,
'excludes': excludes,
}},
)
path = os.path.abspath(os.path.join(os.path.realpath(__file__), os.pardir))
build_path = os.path.join(path, 'build', 'exe.win32-3.7')
shutil.copy(r'C:inPython37-32DLLs cl86t.dll', build_path)
shutil.copy(r'C:inPython37-32DLLs k86t.dll', build_path)
任何人都可以运行python setup.py build_exe
生成可执行文件,或运行python setup.py bdist_msi
生成安装程序。
这篇关于如何在pyinstaller中只包含需要的模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在pyinstaller中只包含需要的模块?


基础教程推荐
猜你喜欢
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 包装空间模型 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
- 求两个直方图的卷积 2022-01-01