【问题标题】:Error when importing pyqtgraph jupyter notebook导入pyqtgraph jupyter notebook时出错
【发布时间】:2019-06-11 10:16:09
【问题描述】:

运行 import pyqtgraph as pg

后出现此错误
ImportError                               Traceback (most recent call last)
<ipython-input-2-952aa750c92c> in <module>()
      6 import contextlib
      7
----> 8 import pyqtgraph as pg
      9 import pqtgraph.opengl as gl
     10

~\AppData\Local\conda\conda\envs\3dTracker\lib\site-packages\pyqtgraph\__init__.py in <module>()
     11 ## 'Qt' is a local module; it is intended mainly to cover up the differences
     12 ## between PyQt4 and PySide.
---> 13 from .Qt import QtGui
     14
     15 ## not really safe--If we accidentally create another QApplication, the process hangs (and it is very difficult to trace the cause)

~\AppData\Local\conda\conda\envs\3dTracker\lib\site-packages\pyqtgraph\Qt.py in <module>()
    131 elif QT_LIB == PYQT4:
    132
--> 133     from PyQt4 import QtGui, QtCore, uic
    134     try:
    135         from PyQt4 import QtSvg

ImportError: cannot import name 'QtGui'

Windows 10 在 jpyter 笔记本中运行 3.5.6 |蟒蛇公司| (默认,2018 年 8 月 26 日,16:05:27)[MSC v.1900 64 位 (AMD64)]

我有一些使用 pyqtgraph 的代码,今天我意识到我无法运行这些程序。在他们完美运行之前。 我记得唯一改变环境的就是安装 pandas。

我尝试重新安装 pyqtgraph 和 pyqt 没有成功

【问题讨论】:

    标签: python pyqt anaconda pyqtgraph


    【解决方案1】:

    PyQtGraph 自动确定安装了哪个 Qt 版本。默认情况下,它首先查找 PyQt4,然后是 PySide,最后是 PyQt5。查看您的堆栈跟踪,似乎有一些旧的、损坏的 PyQt4 安装,它试图导入但没有成功。

    您可以通过将PYQTGRAPH_QT_LIB 环境变量设置为PyQt5 来强制PyQtGraph 使用PyQt5。设置环境变量后,您可能需要重新启动 Jupyter。

    【讨论】:

    • 你完全正确!!!非常感谢!!更具体地说,我通过以下几行解决了问题 >> import os >> os.environ['PYQTGRAPH_QT_LIB'] = 'PyQt5'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-10
    • 2019-02-13
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    相关资源
    最近更新 更多