在REAPER中多次运行PyQt4脚本会导致SIP错误

问题描述 投票:0回答:1

一些上下文:REAPER是一个数字音频工作站,有一个带有Lua,Python,C / C ++和EEL绑定的extensive scripting API。我没有找到很多关于它如何在内部处理Python的信息。从表面上看,配置涉及指向系统某处的Python DLL。截图

问题:我尝试运行在REAPER中找到here的PyQt4脚本的修改版本。起初它工作得很好

在随后运行相同的脚本时,会弹出一个错误:

 Traceback (most recent call last):
  File "pyqt_test.py", line 2, in <module>
    from PyQt4 import QtGui
RuntimeError: the sip module has already registered a module called PyQt4.QtCore

重新启动REAPER解决了另一次运行脚本的问题,然后再次显示相同的错误。

谷歌搜索这个问题并没有多大帮助。在PyQt邮件列表上有one message提到错误,解决方案涉及一个包的__init__文件,但没有其他详细说明。

这是我正在运行的修改后的脚本:

import sys
from PyQt4 import QtGui

def main():
    sys.argv = [] # necessary because for some reason argv doesnt exist when the script is run inside REAPER

    app = QtGui.QApplication(sys.argv)
    widget = QtGui.QWidget()
    layout = QtGui.QGridLayout()

    buttons = {}

    for i in range(16):
        for j in range(16):
            # keep a reference to the buttons
            buttons[i, j] = QtGui.QPushButton('row %d, col %d' % (i, j))
            # add to the layout
            layout.addWidget(buttons[i, j], i, j)

    widget.setLayout(layout)
    widget.show()
    app.exit(app.exec_())

if __name__ == '__main__':
    RPR_defer('main()') # RPR_defer runs supplied code in REAPER's GUI thread.

关于发生了什么以及如何解决/解决它的任何想法?

python pyqt pyqt4 python-sip reaper
1个回答
0
投票

使用Python ReaScript API多次导入外部库存在一个已知错误。它也发生在numpy(因此所有依赖它的库)。

我一直在努力通过编写reapy库来解决它。它允许从REAPER外部调用ReaScript API的函数(例如在通常的终端中),从而安全地导入任何第三方库(包括PyQt4)。如果您有兴趣,可以查看documentationrepository

© www.soinside.com 2019 - 2024. All rights reserved.