当我运行这个脚本“python3 script.py”时,一切正常。 (我尝试以 root 身份运行脚本,也尝试以其他用户身份运行脚本)
import music21
import os
# "qt.qpa.xcb: could not connect to display"
# "qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found."
os.putenv("QT_QPA_PLATFORM", "offscreen") #handle error above in my case
us = music21.environment.UserSettings()
us['musescoreDirectPNGPath'] = '/usr/bin/musescore3'
score = music21.converter.parse("myfile.musicxml")
score.write('musicxml.pdf', fp='song.pdf')
但是当我的 django 后端必须将此代码作为函数执行以响应 API 调用时,它不起作用。我得到:
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-myusername'
This plugin does not support propagateSizeHints()
如果我删除带有“QT_QPA_PLATFORM”的部分,我会收到“qt.qpa.xcb”错误。 我不知道该怎么办。 我还尝试在 Gunicorn 设置脚本中添加以下行,但没有任何改变。
export QT_QPA_PLATFORM=offscreen
有什么解决办法吗?可能出什么问题了?
服务器操作系统:Ubuntu 20.04