对于想了解尝试构建--onefile时,PyQt出现PyInstaller错误的读者,本文将是一篇不可错过的文章,并且为您提供关于pycharm+PyQt5开发配置py转exepyinstaller、
对于想了解尝试构建--onefile时,PyQt出现PyInstaller错误的读者,本文将是一篇不可错过的文章,并且为您提供关于pycharm+PyQt5 开发配置 py 转 exe pyinstaller、pyinstall 打包pyqt5文件、PyInstaller 1.5.1 发布,Python 打包工具、PyInstaller 2.0 发布,Python 应用打包工具的有价值信息。
本文目录一览:- 尝试构建--onefile时,PyQt出现PyInstaller错误
- pycharm+PyQt5 开发配置 py 转 exe pyinstaller
- pyinstall 打包pyqt5文件
- PyInstaller 1.5.1 发布,Python 打包工具
- PyInstaller 2.0 发布,Python 应用打包工具
尝试构建--onefile时,PyQt出现PyInstaller错误
我正在尝试使用PyInstaller 1.5编译PyQt程序。当我使用–
onedir(默认设置)时,以下两个程序对我来说都工作正常,但这会创建相当大的程序。我想使用–
onefile选项,但是在运行创建的onefile应用程序时,出现错误消息:
Traceback (most recent call last): File "<string>", line 11, in <module> File "pyinstaller/PyInstaller/loader/iu.py", line 468, in importHookraise ImportError("No module named %s" % fqname)ImportError: No module named PyQt4.QtCore
这两个都发生此错误:
import sys from PyQt4 import QtCore, QtGuiapp =QtGui.QApplication(sys.argv) window =QtGui.QMainWindow() window.setCentralWidget(QtGui.QLabel("Hello")) window.show() sys.exit(app.exec_())
和这个:
import sysimport PyQt4.QtCore, PyQt4.QtGuiapp = PyQt4.QtGui.QApplication(sys.argv) window = PyQt4.QtGui.QMainWindow() window.setCentralWidget(PyQt4.QtGui.QLabel("Hello")) window.show() sys.exit(app.exec_())
有人有什么想法吗?
答案1
小编典典1,Pyinstaller不会创建比–onedir小的–onefile。运行–
onefile时,它只是创建一个包装程序,将目录中的所有内容提取到一个临时目录中,然后运行它。
2,Pyinstaller不支持import PyQt4.QtCore, PyQt4.QtGui
,并且from PyQt4 importQtCore,QtGui
是根据唯一支持的方式在这里。
3,您的PyQt4是什么版本?是Riverbank安装程序的GPL版本吗?
4,您是否正确按照步骤进行?例如,Makespec.py
然后Build.py
?
pycharm+PyQt5 开发配置 py 转 exe pyinstaller
一、#转exe文件需要安装的包
1、pip install pywin32
2、pip install pyinstaller
3、设置好环境变量 执行 pyinstaller -F test.py #在文件夹下新建了dist文件夹,exe文件就放在里面
二、pyqt安装
1、pip3 install PyQt5
2、pip3 install PyQt5-tools
3、以上模块都安完,设置扩展工具的参数找到 setting->tools->external tools, 点击加号新建工具
4、先加 qtdesinger 的参数,program:E:\python_study\qtstudy\venv\Lib\site-packages\pyqt5-tools\designer.exe, 这个是我的需要换成你自己的,
parameter:空着,working directory:FileDirFileDir, 后面这个可以和我一样
6、再点加号,添加 pyuic5 的参数,这个是把 qt 的 UI 文件转换成.py 文件的工具,program:E:\python_study\qtstudy\venv\Scripts\pyuic5.exe,这个也需要改成你自己的,
arguments:$FileName$ -o $FileNameWithoutExtension$.py ,working directory:FileDirFileDir, 后面这个可以和我一样
7、再点加号,添加 pyrcc 的参数,这个是将资源文件如图片等转成 python 代码能识别的文件,这个参数基本和 pyuic5 的是一样的
8、以上参数配置完成 PYQT5 也可以说是基本完成了,如果你是顺利基本可以装 B 了
9、直接打开 qtdesinger,创建一个 UI 文件,保存在 python 工程的本地目录,如果保存没反应就用另存为,这样在工程里就会出现 qt 的 UI 文件了
10、右键保存好的 ui 文件,选择 external tools->pyuic5 生成代码 py 文件
11、运行一下主 py 文件吧,成功了吧,我只是测试加了一个编辑框,其它的你们可以自己试试了
pyinstall 打包pyqt5文件
1、环境: python3.6(Anaconda3安装包带的) pyinstaller(3.3.1)
2、打包单文件
先测试了一下hello.py在python控制台内可以运行,接着用pyinstaller的打包命令将其打包,但打包后的exe无法运行
3、上网搜索了一下,说是缺少platform文件。但是按照网上教程所说的将D:\Qt\Qt5.9.4\5.9.4\msvc2017_64\plugins\platforms(本机电脑路径)文件夹拷贝到exe所在目录,仍然无法运行。细细琢磨一下,可能需要python路径下的qt相关platforms,然后就在Anaconda3(本人用的python是Anaconda3自带的)目录下搜索platforms文件夹,还真找到了:
将本文件夹拷贝到exe目录,exe得以运行,bingo!
将.ui资源文件打包进exe的方法:
1、hello.py,可正常运行
代码如下:
import os,sys
from PyQt5.QtWidgets import QWidget,QApplication
from PyQt5 import uic
class Hello(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
if getattr(sys, ''frozen'', False):
''''''打包之后,资源文件的路径改变''''''
dir = sys._MEIPASS
else:
dir = os.path.dirname(os.path.abspath(__file__))
print(dir)
uic.loadUi(dir + ''/hello.ui'',self)
self.show()
if __name__ == ''__main__'':
app = QApplication(sys.argv)
hi = Hello()
sys.exit(app.exec_())
2、确认python正常环境运行无误后,用pyinstaller将之打包
3、将platforms文件拷贝到dist,exe可以运行
PyInstaller 1.5.1 发布,Python 打包工具
PyInstaller 是一个用来将 Python 程序打包成一个独立可执行软件包,支持 Windows、Linux 和 Mac OS X。
PyInstaller 1.5.1 发布,更新如下:
Changes: A new default PyInstaller icon was added for generated executables on Windows. Support was added for Python built with --enable-shared on Mac OS X. A workaround was added for incorrect platform.system() on some Python Windows installations where this function returns "Microsoft" instead "Windows". The --windowed option was fixed for Mac OS X, where a console executable was created every time even with this option. A typographical error that prevented detection of DLL libraries loaded by the ctypes module was fixed.
PyInstaller 2.0 发布,Python 应用打包工具
PyInstaller 2.0 发布了,PyInstaller 是一个用来将 Python 程序打包成一个独立可执行软件包,支持 Windows、Linux 和 Mac OS X。
该版本要求至少 Python 2.3,增加对 AIX 和 Solaris 平台的支持,支持 OS X 10.7 和 10.8 ,简化了命令行接口,改进对 PyUSB, wx, Tkinter, PyQt4, pyttsx, win32com, 和 pyenchant 的支持,可在 OS X 平台上创建 .app 应用包,使用 Python 日志系统做为消息输出,大量的代码重构,源码移到 github 上。
关于尝试构建--onefile时,PyQt出现PyInstaller错误的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于pycharm+PyQt5 开发配置 py 转 exe pyinstaller、pyinstall 打包pyqt5文件、PyInstaller 1.5.1 发布,Python 打包工具、PyInstaller 2.0 发布,Python 应用打包工具的相关信息,请在本站寻找。
本文标签: