mac上qt5開(kāi)發(fā)python界面配置

安裝

當(dāng)然選擇brew安裝

brew install python3
brew install pyqt5
brew cask install qt-creator #用于圖形界面UI的編寫(xiě)

pyqt5的工具鏈配置
配置Qt Designer

Tools->External Tools-> +
Name: Qt Designer 
Description: 生成.ui文件 
Program: /Users/kirin/Qt5.8.0/5.8/clang_64/bin/Designer.app 
Parameters: $FilePath$ 
Working directory: $ProjectFileDir$ 

配置好以后, 在.ui文件右鍵"External Tools->Qt Designer", 可以在Qt Designer中編輯這個(gè).ui文件

配置PyUIC5

Tools->External Tools-> +
Name: PyUIC5 
Description: 將.ui文件轉(zhuǎn)為.py文件 
Program: pyuic5 
Parameters: $FilePath$ -o $FileDir$/$FileNameWithoutExtension$.py 
Working directory: $ProjectFileDir$

配置好以后, 在.ui文件右鍵"External Tools->PyUIC5", 可以調(diào)用命令轉(zhuǎn)成.py文件

打包

pip install pyinstaller 
sudo pyinstaller -w -y hello.py

完成后在dist目錄可看到.app文件

問(wèn)題

1.打包后 mac 上顯示模糊

需要設(shè)置打包后的.spec 文件,添加NSHighResolutionCapable項(xiàng)

app = BUNDLE(exe,
         name='myscript.app',
         icon=None,
         bundle_identifier=None
         info_plist={
            'NSHighResolutionCapable': 'True'
            },
         )

2.怎么使用配置的.spec 文件進(jìn)行打包

sudo pyinstaller -w -y hello.spec

3.打包后因?yàn)檎也坏阶约毫硗馕募A的module閃退

打包時(shí)使用-p 配置module 路徑,如
sudo pyinstaller -w -y main.py -p /Users/xxx/Desktop/pathOfModule/
也可以在.spec 文件內(nèi)配置好


a = Analysis(['main.py'],
             pathex=['/Users/xxx/Desktop/pathOfModule1/', '/Users/xxx/Desktop/pathOfModule2/'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

4.使用selenium打包后閃退

使用webdriver的時(shí)候傳入executable_path,如果需要打包給其它機(jī)器使用,應(yīng)該把chromedriver文件也拷貝到對(duì)應(yīng)路徑

path = '/usr/local/bin/chromedriver'
webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=cap, executable_path=path)

好像在.spec文件內(nèi)添加binaries可以把執(zhí)行文件打包進(jìn)APP,暫時(shí)未嘗試了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容