python 代码打包成可执行文件 pyinstaller

1.打包为一个目录

  pyinstaller -D xxx.py

2.打包为一个文件

  pyinstaller -F xxx.py

打包过程中会生成一个xxx.spec文件,如果有自定义的引用,可以修改这个文件,然后执行

  pyinstaller xxx.spec

xxx.spec 文件结构如下:

复制代码
# -*- mode: python ; coding: utf-8 -*-


block_cipher = None


a = Analysis(
    ['mainx.py'],
    pathex=[],
    binaries=[],  
    datas=[], #此处可加入自定义的文件
    hiddenimports=[],  #此处可以引入自定义的模块
    hookspath=[],
    hooksconfig={},
    runtime_hooks=[],
    excludes=[],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=block_cipher,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)

exe = EXE(
    pyz,
    a.scripts,
    [],
    exclude_binaries=True,
    name='mainx',
    debug=False,
    bootloader_ignore_signals=False,
    strip=False,
    upx=True,
    console=True,
    disable_windowed_traceback=False,
    argv_emulation=False,
    target_arch=None,
    codesign_identity=None,
    entitlements_file=None,
)
coll = COLLECT(
    exe,
    a.binaries,
    a.zipfiles,
    a.datas,
    strip=False,
    upx=True,
    upx_exclude=[],
    name='mainx',
)
复制代码

 

posted on   空明流光  阅读(220)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
历史上的今天:
2020-11-10 C# 增加 IIS 默认主页文档
2020-11-10 C# 解压缩ZIP文件
2017-11-10 asp.net IE11 dopostback is null or undefined 为空或未定义
2015-11-10 asp.net httpmodule 访问页面控件 备忘

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示