对于想了解例外:尽管没有使用PyQt5,但是在使用Pyinstaller时找不到PyQt5插件目录的读者,本文将是一篇不可错过的文章,并且为您提供关于1、PyQt5-在VSCode上使用PyQt5、G
对于想了解例外:尽管没有使用PyQt5,但是在使用Pyinstaller时找不到PyQt5插件目录的读者,本文将是一篇不可错过的文章,并且为您提供关于1、PyQt5-在VSCode上使用PyQt5、GUI编程--基于PyQt5(8)-安装PyQt5时缺少designer.exe、pycharm+PyQt5 开发配置 py 转 exe pyinstaller、pyinstall 打包pyqt5文件的有价值信息。
本文目录一览:- 例外:尽管没有使用PyQt5,但是在使用Pyinstaller时找不到PyQt5插件目录
- 1、PyQt5-在VSCode上使用PyQt5
- GUI编程--基于PyQt5(8)-安装PyQt5时缺少designer.exe
- pycharm+PyQt5 开发配置 py 转 exe pyinstaller
- pyinstall 打包pyqt5文件
例外:尽管没有使用PyQt5,但是在使用Pyinstaller时找不到PyQt5插件目录
一个月前,我解决我的applcation冻结问题为Python
2.7,你可以看到在这里。此后,我将代码修改为适用于python
3.5(使用Anaconda),它似乎正在运行。pyinstaller无法与Anaconda一起使用,因此切换为尝试使用标准Python3.5编译器生成.exe。我使用的链接与(pyinstaller --additional-hooks-dir=. --clean --win-private-assemblies pipegui.py
)上方的设置相同,除了我收到以下错误消息:
`Exception: Cannot find PyQt5 plugin directories`
这可能有关吗?除了我使用的是Pyinstaller之外,我没有setup.py,所以根本不知道如何使用该解决方案。
我发现此错误消息很奇怪,因为我没有使用PyQt5,而是使用PyQt4。这是完整的输出:
C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src>pyinstaller --additional-hooks-dir=. --clean --win-private-assemblies pipegui.py
62 INFO: PyInstaller: 3.2
62 INFO: Python: 3.5.0
62 INFO: Platform: Windows-10.0.14393
62 INFO: wrote C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src\pipegui.spec
62 INFO: UPX is not available.
62 INFO: Removing temporary files and cleaning cache in C:\Users\Cornelis Dirk Haupt\AppData\Roaming\pyinstaller
62 INFO: Extending PYTHONPATH with paths
['C:\\Users\\Cornelis Dirk Haupt\\PycharmProjects\\Mesoscale-Brain-Explorer','C:\\Users\\Cornelis Dirk '
'Haupt\\PycharmProjects\\Mesoscale-Brain-Explorer\\src']
62 INFO: checking Analysis
62 INFO: Building Analysis because out00-Analysis.toc is non existent
62 INFO: Initializing module dependency graph...
62 INFO: Initializing module graph hooks...
62 INFO: Analyzing base_library.zip ...
1430 INFO: running Analysis out00-Analysis.toc
1727 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-math-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",line 695,in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",line 122,in _getImports_pe
dll,_ = sym.forwarder.split('.')
TypeError: a bytes-like object is required,not 'str'
1742 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-runtime-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1742 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-locale-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1758 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-stdio-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1758 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-heap-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1774 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-string-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1774 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-environment-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1774 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-time-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1789 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-filesystem-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1789 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-conio-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1789 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-process-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1805 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-convert-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py",not 'str'
1805 INFO: Caching module hooks...
1805 INFO: Analyzing C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src\pipegui.py
1992 INFO: Processing pre-find module path hook distutils
2055 INFO: Processing pre-safe import module hook six.moves
3181 INFO: Processing pre-find module path hook site
3181 INFO: site: retargeting to fake-dir 'c:\\users\\cornelis dirk haupt\\appdata\\local\\programs\\python\\python35\\lib\\site-packages\\PyInstaller\\fake-modules'
4298 INFO: Processing pre-safe import module hook win32com
9975 INFO: Loading module hooks...
9975 INFO: Loading module hook "hook-_tkinter.py"...
10121 INFO: checking Tree
10121 INFO: Building Tree because out00-Tree.toc is non existent
10122 INFO: Building Tree out00-Tree.toc
10184 INFO: checking Tree
10184 INFO: Building Tree because out01-Tree.toc is non existent
10185 INFO: Building Tree out01-Tree.toc
10198 INFO: Loading module hook "hook-matplotlib.py"...
10404 INFO: Loading module hook "hook-pywintypes.py"...
10526 INFO: Loading module hook "hook-xml.py"...
10526 INFO: Loading module hook "hook-pydoc.py"...
10527 INFO: Loading module hook "hook-scipy.linalg.py"...
10527 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
10529 INFO: Loading module hook "hook-plugins.py"...
10721 INFO: Processing pre-find module path hook PyQt4.uic.port_v3
10726 INFO: Processing pre-find module path hook PyQt4.uic.port_v2
12402 INFO: Loading module hook "hook-OpenGL.py"...
12583 INFO: Loading module hook "hook-PyQt4.QtGui.py"...
12802 INFO: Loading module hook "hook-encodings.py"...
12807 INFO: Loading module hook "hook-PyQt4.uic.py"...
12812 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
12813 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
12813 INFO: Loading module hook "hook-setuptools.py"...
12814 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
12814 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
Traceback (most recent call last):
File "<string>",line 2,in <module>
ImportError: DLL load failed: The specified procedure could not be found.
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\runpy.py",line 170,in _run_module_as_main
"__main__",mod_spec)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\runpy.py",line 85,in _run_code
exec(code,run_globals)
File "C:\Users\Cornelis Dirk Haupt\AppData\Local\Programs\Python\Python35\Scripts\pyinstaller.exe\__main__.py",line 9,in <module>
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\__main__.py",line 90,in run
run_build(pyi_config,spec_file,**vars(args))
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\__main__.py",line 46,in run_build
PyInstaller.building.build_main.main(pyi_config,**kwargs)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py",line 788,in main
build(specfile,kw.get('distpath'),kw.get('workpath'),kw.get('clean_build'))
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py",line 734,in build
exec(text,spec_namespace)
File "<string>",line 16,in <module>
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py",line 212,in __init__
self.__postinit__()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\datastruct.py",line 178,in __postinit__
self.assemble()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py",line 470,in assemble
module_hook.post_graph()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\imphook.py",line 409,in post_graph
self._load_hook_module()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\imphook.py",line 376,in _load_hook_module
self.hook_module_name,self.hook_filename)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\compat.py",line 725,in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>",line 385,in _check_name_wrapper
File "<frozen importlib._bootstrap_external>",line 806,in load_module
File "<frozen importlib._bootstrap_external>",line 665,in load_module
File "<frozen importlib._bootstrap>",line 268,in _load_module_shim
File "<frozen importlib._bootstrap>",line 693,in _load
File "<frozen importlib._bootstrap>",line 673,in _load_unlocked
File "<frozen importlib._bootstrap_external>",line 662,in exec_module
File "<frozen importlib._bootstrap>",line 222,in _call_with_frames_removed
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtCore.py",line 15,in <module>
binaries = qt_plugins_binaries('codecs',namespace='PyQt5')
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\utils\hooks\qt.py",line 64,in qt_plugins_binaries
pdir = qt_plugins_dir(namespace=namespace)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\utils\hooks\qt.py",line 38,in qt_plugins_dir
raise Exception('Cannot find {0} plugin directories'.format(namespace))
Exception: Cannot find PyQt5 plugin directories
我会说我也不知道该怎么做。TypeError: a bytes-like object is required,not
'str'
这可能有关吗?据我只能告诉我,这是我唯一的用法:
pickle.dump( roiState,open( fileName,"wb" ) )
roiState = pickle.load(open(fileName,"rb"))
运行应用程序时没有任何错误,仅在尝试使用pyinstaller生成.exe时出现这些错误。为什么?
还要注意,Anaconda3确实会在上面的回溯中弹出(为什么要在其中查找二进制文件?),但是我:
- 从Anaconda卸载了pyinstaller
- 我正在使用标准的Python 3.5(64位)编译器
我唯一想到的可能是罪魁祸首是我不再使用Pyinstaller的开发人员版本(它只是在Python
3.5中无法运行)。在为python2.7编写代码时,我不得不使用开发人员版本来解决冻结问题。
1、PyQt5-在VSCode上使用PyQt5
一、安装Python
安装方法请参考链接:1、Python-Python环境的安装
二、安装Python插件
安装PyQt5所需要的插件:PyQt5、PyQt5-tools
安装方法请参考链接:2、Python-Python插件的安装
三、安装VSCode及其插件:
安装PyQt5所需要的的插件:PYQT Integration
安装方法请参考链接:3、Python-在VSCode上搭建Python开发环境
四、开启Qt Designer并创建对话框
打开一个文件夹,如 “Demo”,在 “DEMO” 下拉框的空白处点击鼠标右键找到 “PYQT:New Form”并点击鼠标左键。
从 Python 的安装路径找到 “designer.exe”("D:\Python\Python39\Lib\site-packages\qt5_applications\Qt\bin\designer.exe")。
选择 “打开” 后就会打开 Qt Designer,此时就可以选择创建一个 Dialog。
对界面进行简单的修改,然后保存到 “Demo” 文件夹中。
可以在 Vscode 中看到保存的.ui 文件。
将.ui 文件转换成.py 文件,右击.ui 文件选择 “PYQT:Compile Form”。
转换完成的.py 文件直接运行并不会有任何界面显示,需要后面进行完善。
五、编写基于PyQt5的启动代码
创建一个自己的.py 文件,如 "mydialog.py",在文件中添加如下程序。
1. 下面是基于创建Dialog类型的界面编写的启动代码:
import sys
from PyQt5.QtWidgets import *
from Ui_hello_dialog import *
class MyDialog(QDialog):
def __init__(self) -> None:
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
pass
if __name__ == "__main__":
app = QApplication(sys.argv)
my_dialog = MyDialog()
my_dialog.show()
sys.exit(app.exec())
2. 下面是基于创建MainWindow类型的界面编写的启动代码:
import sys
from PyQt5.QtWidgets import *
from Ui_hello_window import *
class MyWindow(QMainWindow):
def __init__(self) -> None:
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
pass
if __name__ == "__main__":
app = QApplication(sys.argv)
my_window = MyWindow()
my_window.show()
sys.exit(app.exec())
六、运行结果
运行 “mydialog.py” 文件(不要直接点击运行按钮,注意要选择运行 Python 文件)即可看到创建的对话框。
七、总结
相比于Python自带的Tkinter,PyQt5设置界面要方便的多,也很直观,但比不上直接使用Qt,非专业人员可以将就使用。至于PyQt5的具体使用请参看:PyQt - 主要类 (Major Classes)_学习 PyQt|WIKI 教程 (iowiki.com)
GUI编程--基于PyQt5(8)-安装PyQt5时缺少designer.exe
一般来讲,Qt Designer要么包含在PyQt5中,要么就在pyqt5-tools中,所以我们可以直接通过“pip3 install PyQt5”或者是‘pip3 install pyqt5-tools’安装
详细的安装教程可在B站查看:搜索“”“撩课-Python-GUI编程-PyQt5”视频第100节有讲Qt Designer的安装方法,以及如何在pycharm中添加进来。
但问题是:安装后找不到designer.exe文件。可按以下方法查找。
1.位于当前python环境
环境名Scripts\designer.exe(正常情况下应该在这里)
2.位于当前python环境
环境名/Lib\site-packages\pyqt5-tools\designer.exe
3.位于当前python环境
环境名\Lib\site-packages\qt5_applications/Qt\bin/designer.exe
我的就在:D:\anaconda\envs\monai\Lib\site-packages\qt5_applications\Qt\bin
它是一个可执行程序,可以双击点开的。
如果你找不到,可以通过软件(Everything)搜索designer.exe.搜索速度非常快
以上方法适用于windows,mac没有designer.exe.
如何把这个exe文件添加到pycharm里面
一次点击 file > settings > External tools > +号
根据下图定义
设置好后点击应用即可。
如何使用
设置完后,可以 菜单栏 Tools > External tools > Qt 设计师 就可出现如下画面、
学会了吗?学会了点个赞再走~~
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可以运行
今天的关于例外:尽管没有使用PyQt5,但是在使用Pyinstaller时找不到PyQt5插件目录的分享已经结束,谢谢您的关注,如果想了解更多关于1、PyQt5-在VSCode上使用PyQt5、GUI编程--基于PyQt5(8)-安装PyQt5时缺少designer.exe、pycharm+PyQt5 开发配置 py 转 exe pyinstaller、pyinstall 打包pyqt5文件的相关知识,请在本站进行查询。
本文标签: