Python 在pycharm中使用matplotlib时出现错误“无法找到或加载Qt平台插件窗口”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41994485/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error "could not find or load the Qt platform plugin windows" while using matplotlib in pycharm
提问by Daivik Paul
I am getting the error "could not find or load the Qt platform plugin windows" while using matplotlib in PyCharm.
在 PyCharm 中使用 matplotlib 时出现错误“无法找到或加载 Qt 平台插件窗口”。
How can I solve this?
我该如何解决这个问题?
回答by cxxl
I had the same problem with Anaconda3 4.2.0 and 4.3.0.1 (64-bit). When I tried to run a simple program that uses matplotlib, I got this error message:
我在 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.
Reinstalling didn't fix it.
重装也没解决。
What helped was this (found here):
Look for the Anaconda directory and set the Library\plugins
subdir (here c:\ProgramData\Anaconda3\Library\plugins
) as environment variable QT_PLUGIN_PATH
under Control Panel / System / Advanced System Settings / Environment Variables.
有什么帮助(在此处找到):查找 Anaconda 目录并将子目录Library\plugins
(此处c:\ProgramData\Anaconda3\Library\plugins
)设置为QT_PLUGIN_PATH
控制面板/系统/高级系统设置/环境变量下的环境变量。
After setting the variable you might need to restart PyCharm, if the change does not have an immediate effect.
设置变量后,如果更改没有立即生效,您可能需要重新启动 PyCharm。
Et voilà!
等等!
Update:Even though after that the command line Python worked, TexWorks (which uses Qt as well) displayed an error message very much like it. Setting the QT_PLUGIN_PATH
to the directory containing TexWorks' Qt DLLs (here C:\Users\chris\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64
) fixed the problem for both programs.
更新:即使在命令行 Python 工作之后,TexWorks(也使用 Qt)显示了与它非常相似的错误消息。将 设置为QT_PLUGIN_PATH
包含 TexWorks 的 Qt DLL 的目录(此处C:\Users\chris\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64
)修复了两个程序的问题。
回答by Richard Ayling
I found that this was being caused by having the MiKTeX binaries in my PATH variable; and the wrong Qt dll's were being found. I just needed to re-arrange the PATH entries.
我发现这是由于我的 PATH 变量中有 MiKTeX 二进制文件引起的;并且发现了错误的 Qt dll。我只需要重新排列 PATH 条目。
(Dependency Walkeris such a useful tool.)
(Dependency Walker是一个非常有用的工具。)
回答by launchpadmcquack
I had a similar problem with PyCharm where things worked great in main run but not in debugger, getting the same error message. This happened for me because I had moved my Anaconda installation to a different directory. The debugger goes and checks a qt.conf file that is located at the same place as python. This location can be found by running import sys; print sys.executable
. I found this solution through a pile of web searches and it was buried deep here. The qt.conf file needs to have correct paths for debugger to work.
我在 PyCharm 中遇到了类似的问题,其中在主运行中运行良好,但在调试器中运行良好,收到相同的错误消息。这发生在我身上,因为我已将 Anaconda 安装移动到不同的目录。调试器会检查与 python 位于同一位置的 qt.conf 文件。可以通过运行找到该位置import sys; print sys.executable
。我通过一堆网络搜索找到了这个解决方案,它深埋在这里。qt.conf 文件需要有正确的路径才能让调试器正常工作。
My qt.conf files looks like this in notepad:
我的 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
回答by Shu Zhang
I tried the following in Anaconda prompt, and it solved this problem:
我在 Anaconda 提示符下尝试了以下操作,它解决了这个问题:
conda remove qt
康达删除qt
conda remove pyqt
康达删除pyqt
conda install qt
康达安装qt
conda install pyqt
康达安装pyqt
回答by Osama Adly
If installed PyQt5
and PySide2
, I solved problem
如果安装PyQt5
和PySide2
,我解决的问题
Copy the following files
复制以下文件
\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
to
到
\Anaconda3\Library\plugins\platforms\
回答by Pranzell
Pycharm Console or Debugger showing this issue - Could not find or load the Qt platform plugin windows
显示此问题的 Pycharm 控制台或调试器 -无法找到或加载 Qt 平台插件窗口
Reason - Python exe file may be located at a different location for Pycharm interpreter, you might manually select it in file,settings,interpreter.
原因 - Python exe 文件可能位于 Pycharm 解释器的不同位置,您可以在文件、设置、解释器中手动选择它。
Solution -
解决方案 -
Set the working directory. File ->Settings-> Build, Execution, Deployment ->Console ->Python Console -> Working directory. Set it to parent directory where your all codes are present.
Open Control Panel-> System Settings -> Advanced System Settings ->Environment Variables ->New. Set Variable Name: QT_PLUGIN_PATH, Variable Directory:Users\\Appdata\Local\Continuum\Anaconda2\Library\plugins
Restart Pycharm.
设置工作目录。文件->设置->构建、执行、部署->控制台->Python控制台->工作目录。将其设置为所有代码所在的父目录。
打开控制面板->系统设置->高级系统设置->环境变量->新建。设置变量名:QT_PLUGIN_PATH,变量目录:Users\\Appdata\Local\Continuum\Anaconda2\Library\plugins
重启 Pycharm。
回答by rakidedigama
If you want to visualize your matplotlibs in an alternative way, use a different backend that generates the graphs, charts etc.
如果您想以另一种方式可视化您的 matplotlib,请使用不同的后端来生成图形、图表等。
import matplotlib
matplotlib.use('TKAgg')
import matplotlib
matplotlib.use('TKAgg')
This worked for me.
这对我有用。
回答by kunjung sherpa
Just add a system variable:
只需添加一个系统变量:
QT_QPA_PLATFORM_PLUGIN_PATH and set its value to the C:\Python34\Lib\site-packages\PyQt4\plugins\platforms
QT_QPA_PLATFORM_PLUGIN_PATH 并将其值设置为 C:\Python34\Lib\site-packages\PyQt4\plugins\platforms
Voila. Done
瞧。完毕
回答by Sourabh Desai
I have found a solution that worked for me, follow the link given below. This solution includes a code snippet to add before you import any modules from Pyside2 or PyQt5 package.
我找到了一个对我有用的解决方案,请点击下面给出的链接。 此解决方案包括在从 Pyside2 或 PyQt5 包导入任何模块之前添加的代码片段。
Code Snippet(Available in Link also)
代码片段(也可在链接中找到)
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
'''
This solution works for PyQt5 and PySide2 modules. I don't know if it's relevant or not but I have added QT_PLUGIN_PATH environment variable in the system before.
此解决方案适用于 PyQt5 和 PySide2 模块。我不知道它是否相关,但我之前在系统中添加了 QT_PLUGIN_PATH 环境变量。
#Above solution enabled me test PySide2 scripts in IDLE. However, I faced the same error log when I tried to run a bundled script(exe). With some shallow debug, it's evident that plugin folder itself is missing. I fixed the problem by adding the plugin folder in the appropriate location. "C:\Users\xxxx.spyder-py3\My_QtProjects\Project 1\dist\MyQt_1\PySide2\"
上述解决方案使我能够在 IDLE 中测试 PySide2 脚本。但是,当我尝试运行捆绑脚本(exe)时,我遇到了相同的错误日志。通过一些浅层调试,很明显插件文件夹本身丢失了。我通过在适当的位置添加插件文件夹解决了这个问题。"C:\Users\xxxx.spyder-py3\My_QtProjects\Project 1\dist\MyQt_1\PySide2\"
回答by Daniel G
On Windows
在 Windows 上
1- Copy the folder plastforms: C:\Users\%USERNAME%\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyqt5\qt\plugins\platforms
1- 复制文件夹 plastforms:C:\Users\%USERNAME%\AppData\Roaming\pyinstaller\bincache00_py35_64bit\pyqt5\qt\plugins\platforms
2- Paste the folder platform into the folder location of the file .exe
2- 将文件夹平台粘贴到文件 .exe 的文件夹位置
Example: c:\MyFolder\yourFile.exe c:\MyFolder\platforms
示例:c:\MyFolder\yourFile.exe c:\MyFolder\platforms