【问题标题】:Importing qtopengl in to Python 3 on Ubuntu 14.04在 Ubuntu 14.04 上将 qtopengl 导入 Python 3
【发布时间】:2014-11-06 20:53:56
【问题描述】:

这与 this question 有关,但适用于 Python 3 而不是 2.x

我正在尝试在 Python 3.4 (Ubuntu 14.04) 下运行 pyqtgraph 示例程序。当我尝试运行表面绘图示例时,我得到:

tim@MERLIN:/usr/local/lib$ python3 -m pyqtgraph.examples
Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/pyqtgraph-0.9.8-py3.4.egg/pyqtgraph/examples/GLSurfacePlot.py", line 12, in <module>
    import pyqtgraph.opengl as gl
  File "/usr/local/lib/python3.4/dist-packages/pyqtgraph-0.9.8-py3.4.egg/pyqtgraph/opengl/__init__.py", line 1, in <module>
    from .GLViewWidget import GLViewWidget
  File "/usr/local/lib/python3.4/dist-packages/pyqtgraph-0.9.8-py3.4.egg/pyqtgraph/opengl/GLViewWidget.py", line 1, in <module>
    from pyqtgraph.Qt import QtCore, QtGui, QtOpenGL
ImportError: cannot import name 'QtOpenGL'

谁能建议为 Python 3 安装它的最佳方法是什么(在 Python 2.7 下效果很好)?

【问题讨论】:

  • 在阅读了您链接到的那个问题后,您为什么不直接search ubuntu's packages 来查找缺少的python3 模块?这会比在这里发布问题要快得多。
  • @ekhumoro 我已经做到了。这就是为什么我问什么是最好的安装方式。
  • 好吧,您链接到的那个问题中接受的答案建议使用apt-get install python3-pyqt4.qtopengl。然后如果没有 pyqtgraph 的 ubuntu 包,使用python3-pipPyPI 安装它。当然,您也可以尝试从源代码编译所有内容,但如果您不熟悉这样做会更加困难(提示:确保在开始编译之前安装了所有相关的 ubuntu 开发包)。

标签: python opengl python-3.x qt4 pyqt


【解决方案1】:

我刚刚发现 pyqtgraph 在某些情况下无法正确导入 python qt 库。 尝试在代码开头添加:

import PySide

import PyQt5

甚至

import PyQt4

取决于您要默认使用的库。

【讨论】:

    猜你喜欢
    • 2016-04-20
    • 2015-07-08
    • 1970-01-01
    • 2016-08-04
    • 2014-10-05
    • 2014-12-10
    • 2014-08-08
    • 2016-08-13
    相关资源
    最近更新 更多