Python “如何修复”;无法找到或加载Qt平台插件windows“;在PyCharm中使用Matplotlib时
我在PyCharm中使用matplotlib时遇到错误“无法找到或加载Qt平台插件窗口” 我怎样才能解决这个问题Python “如何修复”;无法找到或加载Qt平台插件windows“;在PyCharm中使用Matplotlib时,python,python-3.x,pycharm,Python,Python 3.x,Pycharm,我在PyCharm中使用matplotlib时遇到错误“无法找到或加载Qt平台插件窗口” 我怎样才能解决这个问题 我对Anaconda3 4.2.0和4.3.0.1(64位)也有同样的问题。当我尝试运行使用matplotlib的简单程序时,我收到以下错误消息: This application failed to start because it could not find or load the Qt platform plugin "windows" Reinstalling the a
我对Anaconda3 4.2.0和4.3.0.1(64位)也有同样的问题。当我尝试运行使用matplotlib的简单程序时,我收到以下错误消息:
This application failed to start because it could not find or load the Qt platform plugin "windows"
Reinstalling the application may fix this problem.
重新安装没有修复它
有帮助的是(发现):
查找Anaconda目录,并将Library\plugins
子目录(此处c:\ProgramData\Anaconda3\Library\plugins
)设置为控制面板/System/Advanced System Settings/environment Variables下的环境变量QT\u PLUGIN\u PATH
设置变量后,如果更改没有立即生效,则可能需要重新启动PyCharm
即使在命令行Python运行之后,TexWorks(也使用Qt)显示了一条非常类似的错误消息。将
QT\u PLUGIN\u PATH
设置到包含TexWorks的QT DLL的目录(这里C:\Users\chris\AppData\Local\Programs\MiKTeX 2.9\MiKTeX\bin\x64
)修复了这两个程序的问题。我在PyCharm上也遇到了类似的问题,在主运行中工作得很好,但在调试器中却没有得到相同的错误消息。这种情况发生在我身上,因为我已将我的Anaconda安装移动到另一个目录。调试器将检查与python位于同一位置的qt.conf文件。可通过运行导入系统找到该位置;打印系统可执行文件。我通过一堆网络搜索找到了这个解决方案,它被深深地埋藏了。qt.conf文件需要有正确的路径才能使调试器工作
我的qt.conf文件在记事本中如下所示:
[Paths]
Prefix = E:/python/Anaconda3_py35/Library
Binaries = E:/python/Anaconda3_py35/Library/bin
Libraries = E:/python/Anaconda3_py35/Library/lib
Headers = E:/python/Anaconda3_py35/Library/include/qt
您可能需要复制Anaconda3\Library
中的“插件”文件。例如,在我的电脑上是
S:\Anaconda3\Library\plugins
与.exe文件路径相同。我在Anaconda的提示下尝试了以下操作,解决了此问题:
conda remove qt
conda remove pyqt
conda install qt
conda install pyqt
如果Pycharm控制台或调试器显示“无法找到或加载Qt平台插件窗口”,则Python EXE文件可能位于Pycharm解释器的其他位置。您可以在文件->设置->解释器中手动选择它
QT\u PLUGIN\u PATH
,变量目录:Users\\Appdata\Local\Continuum\Anaconda2\Library\plugins
我发现这是由路径变量中包含MiKTeX二进制文件引起的;发现了错误的Qt dll。我只需要重新排列路径条目
(是一个非常有用的工具。)如果您想以另一种方式可视化MatPlotLib,请使用不同的后端来生成图形、图表等
import matplotlib
matplotlib.use('TKAgg')
这对我有用 在Windows上:
C:\Users\%USERNAME%\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyqt5\qt\plugins\platforms
c:\MyFolder\yourFile.exe
c:\MyFolder\platforms
如果您正在运行PyQt5和PySide2,这就为我解决了问题: 复制以下文件:
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qminimal.dll
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qoffscreen.dll
\Anaconda3\Lib\site-packages\PySide2\plugins\platforms\qwindows.dll
致:
复制文件夹
\Anaconda3\Library\plugins\platforms
到
其中,$
是您的项目解释器文件夹。例如:
"\project\anaconda_env\Scripts\"
因为PyCharm调用此文件夹中的python.exe,而不是在我的情况下调用
\Anaconda3
中的python.exe,所以为了使PyQt5在Windows上运行,我遇到了多个组合问题,请参阅Windows用户的解决方案
使用以下命令创建新的环境变量:
名称:QT_插件_路径
路径:C:\yourpythonpath\Lib\site packages\PyQt5\Qt\plugins
之后,exe文件将工作从Anaconda3\Library\plugins复制平台,并将其放入Anaconda3中。
对于env,将平台放在特定的env\文件夹中我找到了一个适合我的解决方案。此解决方案包括在从Pyside2或PyQt5包导入任何模块之前要添加的代码段。有关详细信息,请参阅“” 此代码段来自以下链接:
import os
import PySide2
dirname = os.path.dirname(PySide2.__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
from PySide2.QtWidgets import *
'''
Your code goes here
'''
此解决方案适用于PyQt5和PySide2模块。
我不知道它是否相关,但我之前在系统中添加了QT\u PLUGIN\u PATH
环境变量
该解决方案使我能够在空闲状态下测试PySide2脚本
然而,当我试图运行捆绑脚本(exe)时,我遇到了相同的错误
通过一些简单的调试,很明显插件文件夹本身丢失了。我通过在适当的位置添加插件文件夹修复了该问题:
C:\Users\xxxx\.spyder-py3\My_QtProjects\Project 1\dist\MyQt_1\PySide2\
只需添加一个系统变量:
QT_QPA_PLATFORM_PLUGIN_PATH
并将其值设置为
C:\Python34\Lib\site-packages\PyQt4\plugins\platforms
瞧。完成我在Qt5.9示例中遇到了同样的问题btscanner.exe。在我的情况下,有效的方法是:
QT_QPA_PLATFORM_PLUGIN_PATH
C:\Python34\Lib\site-packages\PyQt4\plugins\platforms
C:\temp\BlueTouth\btscanner.exe 32 bit, release executable
Adding Qt5Svg for qsvgicon.dll
Skipping plugin qtvirtualkeyboardplugin.dll due to disabled dependencies.
Direct dependencies: Qt5Bluetooth Qt5Core Qt5Gui Qt5Widgets
All dependencies : Qt5Bluetooth Qt5Core Qt5Gui Qt5Widgets
To be deployed : Qt5Bluetooth Qt5Core Qt5Gui Qt5Svg Qt5Widgets
Warning: Cannot find Visual Studio installation directory, VCINSTALLDIR is not set.
Updating Qt5Bluetooth.dll.
Updating Qt5Core.dll.
Updating Qt5Gui.dll.
Updating Qt5Svg.dll.
Updating Qt5Widgets.dll.
Updating libGLESV2.dll.
Updating libEGL.dll.
Updating D3Dcompiler_47.dll.
Updating opengl32sw.dll.
Patching Qt5Core.dll...
Creating directory C:/temp/BlueTouth/iconengines.
Updating qsvgicon.dll.
Creating directory C:/temp/BlueTouth/imageformats.
Updating qgif.dll.
Updating qicns.dll.
Updating qico.dll.
Updating qjpeg.dll.
Updating qsvg.dll.
Updating qtga.dll.
Updating qtiff.dll.
Updating qwbmp.dll.
Updating qwebp.dll.
Creating directory C:/temp/BlueTouth/platforms.
Updating qwindows.dll.
Creating C:\temp\BlueTouth\translations...
Creating qt_bg.qm...
Creating qt_ca.qm...
Creating qt_cs.qm...
Creating qt_da.qm...
Creating qt_de.qm...
Creating qt_en.qm...
Creating qt_es.qm...
Creating qt_fi.qm...
Creating qt_fr.qm...
Creating qt_gd.qm...
Creating qt_he.qm...
Creating qt_hu.qm...
Creating qt_it.qm...
Creating qt_ja.qm...
Creating qt_ko.qm...
Creating qt_lv.qm...
Creating qt_pl.qm...
Creating qt_ru.qm...
Creating qt_sk.qm...
Creating qt_uk.qm...
conda activate myenv
\Anaconda3\Lib\site-packages\PyQt5\Qt\bin to PATH.
pyqt = os.path.dirname(PyQt5.__file__)
os.environ['QT_PLUGIN_PATH'] = os.path.join(pyqt, "Qt/plugins")
# below the line 23 type.__signature__
pyside_package_dir = os.path.abspath(os.path.dirname(__file__))
dirname = os.path.dirname(__file__)
plugin_path = os.path.join(dirname, 'plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path
(base) C:\ProgramData\Miniconda3\Lib\site-packages\PySide2\plugins\platforms>copy *.dll C:\ProgramData\Miniconda3\Library\plugins\platforms\
qt_path= os.path.dirname(PyQt5.__file__)
os.environ['QT_PLUGIN_PATH'] = os.path.join(qt_path, "Qt/plugins")