安裝
當(dāng)然選擇brew安裝
brew install python3
brew install pyqt5
brew cask install qt-creator #用于圖形界面UI的編寫
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中編輯這個.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文件
問題
1.打包后 mac 上顯示模糊
需要設(shè)置打包后的.spec 文件犀暑,添加NSHighResolutionCapable
項
app = BUNDLE(exe,
name='myscript.app',
icon=None,
bundle_identifier=None
info_plist={
'NSHighResolutionCapable': 'True'
},
)
2.怎么使用配置的.spec 文件進行打包
sudo pyinstaller -w -y hello.spec
3.打包后因為找不到自己另外文件夾的module閃退
打包時使用-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的時候傳入executable_path驯击,如果需要打包給其它機器使用,應(yīng)該把chromedriver文件也拷貝到對應(yīng)路徑
path = '/usr/local/bin/chromedriver'
webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=cap, executable_path=path)
好像在.spec文件內(nèi)添加binaries可以把執(zhí)行文件打包進APP耐亏,暫時未嘗試了