pyqt打包_pyinstaller

官網(wǎng)

https://github.com/pyinstaller/pyinstaller
http://www.pyinstaller.org/

安裝

穩(wěn)定版本(反而有bug)

?  pip3 install pyinstaller
?  pyinstaller --version
3.2.1

dev版本(本文寫作是用它)

?  git clone https://github.com/pyinstaller/pyinstaller.git
?  cd pyinstaller
?  python3 setup.py install
?  pyinstaller --version
3.3.dev0+964547c

hello.py 的內(nèi)容

# -*- coding: utf-8 -*-
"""第一個(gè)程序"""
from PyQt5 import QtWidgets
import sys
app = QtWidgets.QApplication(sys.argv)
first_window = QtWidgets.QWidget()
first_window.resize(400, 300)
first_window.setWindowTitle("我的第一個(gè)程序")
first_window.show()
sys.exit(app.exec_())

mac打包

簡(jiǎn)單打包
https://pyinstaller.readthedocs.io/en/stable/usage.html#general-options

?  sudo pyinstaller -w -y hello.py

完成后的目錄

├── __pycache__
├── build
│   └── hello
├── dist
│   ├── hello
│   └── hello.app
│       └── Contents
│           ├── Frameworks
│           ├── Info.plist
│           ├── MacOS
├── hello.py
└── hello.spec

會(huì)多出3個(gè)目錄pycache, build, dist和一個(gè)文件hello.spec

其中的 dist目錄下, 有兩份輸出

dist/hello/          unix的可執(zhí)行目錄(mac下也能運(yùn)行)
dist/hello.app    macOS的程序包(其實(shí)也是一個(gè)目錄)

spec文件

spec文件的作用是什么呢?PyInstaller通過執(zhí)行spec文件中的內(nèi)容來生成app隅忿,有點(diǎn)像makefile。正常使用中我們是不需要管spec文件的盹沈,但是下面幾種情況需要修改spec文件:

  • 需要打包資源文件
  • 需要include一些PyInstaller不知道的run-time庫(kù)
  • 為可執(zhí)行文件添加run-time 選項(xiàng)
  • 多程序打包

也可以通過下面命令生成spec文件
pyi-makespec hello.py

通過下面命令使用spec文件
sudo pyinstaller hello.spec

當(dāng)你使用了spec文件, 那么命令行里的參數(shù)只剩下下面的幾個(gè)還有效, 其它的都被spec文件里的參數(shù)覆蓋了:

參數(shù) 備注
--upx-dir UPX_DIR Path to UPX utility (default: search the execution path)
--distpath DIR Where to put the bundled app (default: ./dist)
--workpath WORKPATH Where to put all the temporary work files, .log, .pyz and etc. (default: ./build)
-y, --noconfirm Replace output directory (default: SPECPATH/dist/SPECNAME) without asking for confirmation
-a, --ascii Do not include unicode encoding support (default: included if available)

spec文件的配置

# -*- mode: python -*-

block_cipher = None

a = Analysis(['main.py'],
             pathex=['/Users/kirin/workspaces/gitlab/pqbox'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='main',
          debug=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='main')

spec文件中主要包含4個(gè)class: Analysis, PYZ, EXE和COLLECT.

  • Analysis以py文件為輸入计维,它會(huì)分析py文件的依賴模塊袜香,并生成相應(yīng)的信息
  • PYZ是一個(gè).pyz的壓縮包,包含程序運(yùn)行需要的所有依賴
  • EXE根據(jù)上面兩項(xiàng)生成
  • COLLECT生成其他部分的輸出文件夾鲫惶,COLLECT也可以沒有

要看更詳細(xì)的文檔在
https://pyinstaller.readthedocs.io/en/stable/usage.html#general-options
https://pyinstaller.readthedocs.io/en/stable/spec-files.html

windows打包

windows下要加--path參數(shù)來找到pyqt的dll

pyinstaller --path C:\Users\Administrator\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\PyQt5\Qt\bin -y -w hello.py
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末蜈首,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子欠母,更是在濱河造成了極大的恐慌欢策,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,843評(píng)論 6 502
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赏淌,死亡現(xiàn)場(chǎng)離奇詭異踩寇,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)六水,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,538評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門俺孙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人掷贾,你說我怎么就攤上這事睛榄。” “怎么了想帅?”我有些...
    開封第一講書人閱讀 163,187評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵场靴,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我港准,道長(zhǎng)旨剥,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,264評(píng)論 1 292
  • 正文 為了忘掉前任浅缸,我火速辦了婚禮轨帜,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘疗杉。我一直安慰自己阵谚,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,289評(píng)論 6 390
  • 文/花漫 我一把揭開白布烟具。 她就那樣靜靜地躺著梢什,像睡著了一般。 火紅的嫁衣襯著肌膚如雪朝聋。 梳的紋絲不亂的頭發(fā)上嗡午,一...
    開封第一講書人閱讀 51,231評(píng)論 1 299
  • 那天,我揣著相機(jī)與錄音冀痕,去河邊找鬼荔睹。 笑死狸演,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的僻他。 我是一名探鬼主播宵距,決...
    沈念sama閱讀 40,116評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼吨拗!你這毒婦竟也來了满哪?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,945評(píng)論 0 275
  • 序言:老撾萬榮一對(duì)情侶失蹤劝篷,失蹤者是張志新(化名)和其女友劉穎哨鸭,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體娇妓,經(jīng)...
    沈念sama閱讀 45,367評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡像鸡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,581評(píng)論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了哈恰。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片只估。...
    茶點(diǎn)故事閱讀 39,754評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖蕊蝗,靈堂內(nèi)的尸體忽然破棺而出仅乓,到底是詐尸還是另有隱情,我是刑警寧澤蓬戚,帶...
    沈念sama閱讀 35,458評(píng)論 5 344
  • 正文 年R本政府宣布,位于F島的核電站宾抓,受9級(jí)特大地震影響子漩,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜石洗,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,068評(píng)論 3 327
  • 文/蒙蒙 一幢泼、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧讲衫,春花似錦缕棵、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,692評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至枷畏,卻和暖如春别厘,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背拥诡。 一陣腳步聲響...
    開封第一講書人閱讀 32,842評(píng)論 1 269
  • 我被黑心中介騙來泰國(guó)打工触趴, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留氮发,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,797評(píng)論 2 369
  • 正文 我出身青樓冗懦,卻偏偏與公主長(zhǎng)得像爽冕,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子披蕉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,654評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容