Pycharm+PyQt5
1.安装PyQt5与pyqt5-tools:在pycharm中安装第三方模块,先安PyQT5,再安装pyqt5-tools,后面包含qtdesinger。
2.两个模块都安完,导入进pycharm:
设置扩展工具的参数找到setting->tools->external tools,点击加号新建工具
3.设置QtDesigner
Name:QtDesigner
Program:designer.exe所在的位置
Arguments:$FileDir$\$FileName$
Working directory:$FileDir$
4.设置PyUIC
Name:PyUIC
Program:pyuic5.exe所在的位置
Arguments:$FileName$ -o $FileNameWithoutExtension$.py
Working directory:$FileDir$
5.将上面数据配置完,就可以在PyCharm中使用QT5了。
6.使用QtDesigner打开QT界面,然后再生成的.ui文件上右键,执行PyUIC,就会自动生成py文件。
将python3.6软件的py文件打包成exe程序——使用pyinstaller
1.安装pyinstaller: pip install pyinstaller
2.进入需要打包的py文件所在的文件夹执行:pyinstaller -F -D -w filename.py
更改exe软件的图标:pyinstaller -F -D -w -i file.ico filename.py
将图标地址(相对路径或者绝对路径均可)跟在-i后面,应为.ico格式,png格式的不行,其他格式未测试。(下载ico的网站https://www.easyicon.net/)
常用参数说明:–i <FILE.ICO>
-F 打包成一个exe文件
-w 使用窗口,无控制台
-c 使用控制台,无窗口
-D 创建一个目录,里面包含exe以及其他一些依赖性文件
-K, --tk 包含TCL/TK
-d, --debug 生成debug模式的exe文件
-w, --windowed, --noconsole 窗体exe文件(Windows Only)
-c, --nowindowed, --console 控制台exe文件(Windows Only)
-o DIR, --out=DIR 设置spec文件输出的目录,默认在PyInstaller同目录
--i <FILE.ICO> 加入图标(Windows Only)
-v FILE, --version=FILE 加入版本信息文件
--upx-dir, 压缩可执行程序
3.返回目标文件目录,发现该目录下生成了.spec文件test.spec,打包好的exe文件,在同目录的dist文件中。
4.将我们在软件中调用的文件(例如xlsx、icon图片等)复制到exe路径下,路径和在软件中写的一致。
5.找到PyQt5包的位置,复制PyQt5->Qt->plugins下的platforms文件夹。将其复制到exe所在目录下。
若不这么做,将产生下面报错。(Reinstalling the application may fix this problem)
6.现在点击生成的exe文件就可以运行了。
解决问题:
AttributeError: module 'enum' has no attribute 'IntFlag'?
pip uninstall enum34 #卸载enum34,This is likely caused by the package enum34. Since python 3.4 there's a standard library enum module, so you should uninstall enum34, which is no longer compatible with the enum in the standard library since enum.IntFlag was added in python 3.6.