第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

pyinstaller利用spec文件打包的使用模板

標(biāo)簽:
Python

pyinstaller打包

使用pyqt5开发软件,当项目越来越大,引用的资源越来越多时,那么使用pyinstaller进行打包,如果不利用spec文件,是很难满足打包需求的。

spec文件,其实你在使用 pyinstaller main.py打包时 ,也是会自动生成的,叫main.spec。

不过,如果你想把自己的资源文件一起打进包去,则需要对spec文件进行一些编辑,然后使用 pyinstaller main.spec即可打包完成。

pyinstaller 基础常规打包方法,网上文章很多了,大家自己搜索也是一大堆,就不一一列举了。这里推荐一篇,刚学习使用pyinstaller时对我帮助最大的文章,同时在此对这位大神作者表示感谢。

本文主要就是列举下pyinstaller利用spec文件进行打包的几个使用模板,以供大家参考使用。至于内涵原理,本人时间有限,也没深入研究,大家根据自己情况去探索吧。

【如下代码,完全复制,直接运行,即可使用】
【注1:模板中的相关路径和文件名称,当然需要根据自己的情况对应修改了】
【注2:如果你的spec文件叫main.spec的话,打包命令便是 pyinstaller main.spec
【注3:当项目越来越大时,免安装绿色文件夹 在软件启动速度上,比单个可执行文件,要快!**】

模式一:使用spec文件,打成【单个可执行文件】

# -*- mode: python -*-

block_cipher = None


a = Analysis(['main.py'],
             pathex=['D:\\PythonProject\\mysoft'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
			 



#######!!!注意点1:加载自己的资源文件#####################
def extra_datas(mydir):
    def rec_glob(p, files):
        import os
        import glob
        for d in glob.glob(p):
            if os.path.isfile(d):
                files.append(d)
            rec_glob("%s/*" % d, files)
    files = []
    rec_glob("%s/*" % mydir, files)
    extra_datas = []
    for f in files:
        extra_datas.append((f, f, 'DATA'))

    return extra_datas

# append the 'Resources' dir
a.datas += extra_datas('Resources')    ###这里是自己的资源文件夹		
a.datas += extra_datas('Reports')	  ###这里是自己的资源文件夹
a.datas += extra_datas('Drivers')	 ###这里是自己的资源文件夹
################################################
			 
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

			 
exe = EXE(pyz,
          a.scripts,
          a.binaries,                          ###!!!注意点2
          a.zipfiles,                          ###!!!注意点2
          a.datas,                             ###!!!注意点2
          [],
          exclude_binaries=False,   ###!!!注意点3:这里是False
          name='mysoft',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False,
          icon='d:\\mysoft.ico')

模式二:使用spec文件,打成【免安装绿色文件夹】

# -*- mode: python -*-

block_cipher = None


a = Analysis(['main.py'],
             pathex=['D:\\PythonProject\\mysoft'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
			 



#######!!!注意点1:加载自己的资源文件#####################
def extra_datas(mydir):
    def rec_glob(p, files):
        import os
        import glob
        for d in glob.glob(p):
            if os.path.isfile(d):
                files.append(d)
            rec_glob("%s/*" % d, files)
    files = []
    rec_glob("%s/*" % mydir, files)
    extra_datas = []
    for f in files:
        extra_datas.append((f, f, 'DATA'))

    return extra_datas

# append the 'Resources' dir
a.datas += extra_datas('Resources')	 ###这里是自己的资源文件夹		
a.datas += extra_datas('Reports')	 ###这里是自己的资源文件夹	
a.datas += extra_datas('Drivers')	 ###这里是自己的资源文件夹	
################################################
			 
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)

			 
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,   ###!!!注意点3:这里是True
          name='mysoft',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False,
          icon='d:\\mysoft.ico')


coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='mysoft')

模式三:使用spec文件,同时打出【单个可执行文件】和【免安装绿色文件夹】

# -*- mode: python -*-

block_cipher = None


a = Analysis(['main.py'],
             pathex=['D:\\PythonProject\\mysoft'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
			 



#######!!!注意点1:加载自己的资源文件#####################
def extra_datas(mydir):
    def rec_glob(p, files):
        import os
        import glob
        for d in glob.glob(p):
            if os.path.isfile(d):
                files.append(d)
            rec_glob("%s/*" % d, files)
    files = []
    rec_glob("%s/*" % mydir, files)
    extra_datas = []
    for f in files:
        extra_datas.append((f, f, 'DATA'))

    return extra_datas

# append the 'Resources' dir
a.datas += extra_datas('Resources')	 ###这里是自己的资源文件夹	
a.datas += extra_datas('Reports')	 ###这里是自己的资源文件夹	
a.datas += extra_datas('Drivers')	 ###这里是自己的资源文件夹	
################################################
			 
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)


exe1 = EXE(pyz,
          a.scripts,
          a.binaries,                          ###!!!注意点2
          a.zipfiles,                          ###!!!注意点2
          a.datas,                             ###!!!注意点2
          [],
          exclude_binaries=False,   ###!!!注意点3:这里是False
          name='mysoft',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False,
          icon='d:\\mysoft.ico')

			 
exe2 = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,   ###!!!注意点3:这里是True
          name='mysoft',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=False,
          icon='d:\\mysoft.ico')


coll = COLLECT(exe2,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='mysoft')

本文如有帮助,敬请留言鼓励。
本文如有错误,敬请留言改进。

點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消