Sphinx Qt ValueError:API' QDate'已经设置为版本1

时间:2017-02-24 16:53:42

标签: python qt pyqt python-sphinx

我正在尝试使用python的Sphinx模块为Qgis(pyqt)插件构建文档(使用Pyqt)。
当尝试使用make html进行构建时, 对于某些模块,我得到了几个例外:

ValueError: API 'QDate' has already been set to version 1

这是完整的堆栈

home/user/path/project.rst:105: WARNING: autodoc: failed to import module u'new_project_base'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/sphinx/ext/autodoc.py", line 551, in import_object
    __import__(self.modname)
  File "/home/rescue/bathydeconfliction/new_project_base.py", line 14, in <module>
    from qgis.core import QgsProject
  File "/usr/lib/python2.7/dist-packages/qgis/__init__.py", line 26, in <module>
    from qgis.PyQt import QtCore
  File "/usr/lib/python2.7/dist-packages/qgis/PyQt/QtCore.py", line 28, in <module>
    sip.setapi(api, 2)
ValueError: API 'QDate' has already been set to version 1

我做错了什么? (在Debian Jessie上使用python 2.7,sphinx 1.5.2)

1 个答案:

答案 0 :(得分:4)

在导入PyQt4之前导入qgis.core已经为我修复了

import  qgis.core 
from PyQt4 import QtCore, QtGui, uic

qgis不是pyqt的一部分,但是当您尝试在相同代码中使用qgis API和PyQt时会发生错误。我相信,原因是qgis定义QDate与PyQt4中的QDate冲突