美文网首页
mac上qt5开发python界面配置

mac上qt5开发python界面配置

作者: he15his | 来源:发表于2018-11-21 17:45 被阅读84次

安装

当然选择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文件转为.py文件 
Program: pyuic5 
Parameters: $FilePath$ -o $FileDir$/$FileNameWithoutExtension$.py 
Working directory: $ProjectFileDir$

配置好以后, 在.ui文件右键"External Tools->PyUIC5", 可以调用命令转成.py文件

打包

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

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

问题

1.打包后 mac 上显示模糊

需要设置打包后的.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 文件内配置好


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,如果需要打包给其它机器使用,应该把chromedriver文件也拷贝到对应路径

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

好像在.spec文件内添加binaries可以把执行文件打包进APP,暂时未尝试了

相关文章

网友评论

      本文标题:mac上qt5开发python界面配置

      本文链接:https://www.haomeiwen.com/subject/gxncqqtx.html