XDG_RUNTIME_DIR,propagateSizeHints() 错误

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

当我运行这个脚本“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

python environment-variables qt5 xcb music21
1个回答
0
投票

您可能还需要设置

XDG_RUNTIME_DIR
。请参阅https://github.com/cuthbertLab/music21/issues/260#issuecomment-834489173

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