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中只包含需要的模块?


基础教程推荐
猜你喜欢
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01