MuseScore
MuseScore copied to clipboard
Can't run MuseScore CLI in headless mode
Issue type
Crash or freeze
Bug description
In MuseScore 3, we could run the MuseScore command-line interface without a display server (for example, on a headless server) by passing the option -platform offscreen
. For example:
$ mscore -platform offscreen -o output.mid input.mscz
This no longer works in MuseScore 4, with or without that option. It fails to start in both cases:
$ mscore -v
QEventLoop: Cannot be used without QApplication
QEventLoop: Cannot be used without QApplication
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.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: eglfs, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, xcb.
$ mscore -platform offscreen -v
QEventLoop: Cannot be used without QApplication
QEventLoop: Cannot be used without QApplication
(mscore:2): Gtk-WARNING **: 11:47:02.947: cannot open display:
Expected behavior: the above two commands should print the MuseScore version (because of -v
flag).
Steps to reproduce
On a Linux machine:
$ unset DISPLAY # remove the DISPLAY env var so MuseScore can't connect to a display server
$ mscore3 -platform offscreen -v
Screenshots/Screen recordings
No response
MuseScore Version
4.0.2 (Flatpak)
Regression
Yes, this used to work in Musescore 3.x and now is broken
Operating system
Ubuntu 22.04.2 LTS
Additional context
No response
The Flatpak version is not supported here, so does the same issue exist with the AppImages?
The Flatpak version is not supported here, so does the same issue exist with the AppImages?
Ah got it. The same issue occurs with the AppImage downloaded from musescore.org, with a slightly different error message:
$ unset DISPLAY
$ ./MuseScore-4.0.2.230651545-x86_64.AppImage -v
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
QEventLoop: Cannot be used without QApplication
QEventLoop: Cannot be used without QApplication
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.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
/tmp/.mount_MuseScfNQmnA/AppRun: line 26: 394950 Aborted (core dumped) "${APPDIR}/bin/mscore4portable" "$@"
$ ./MuseScore-4.0.2.230651545-x86_64.AppImage -platform offscreen -v
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
QEventLoop: Cannot be used without QApplication
QEventLoop: Cannot be used without QApplication
qt.qpa.plugin: Could not find the Qt platform plugin "offscreen" in ""
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb.
/tmp/.mount_MuseScCxj8yw/AppRun: line 26: 394922 Aborted (core dumped) "${APPDIR}/bin/mscore4portable" "$@"
It looks like the offscreen
plugin is not available at all in the AppImage version.
I created a pull request (#17253) which attempts to deploy libqoffscreen.so
to the AppImage. Would be great if you could try the artifacts from that PR when they are ready! (the download link will appear here: https://github.com/musescore/MuseScore/actions/runs/4713219125)
Thanks!! I'm still having some trouble using it headlessly. It seems like MuseScore is trying to parse the -platform
option as one of its own options. I think that option should be handled by Qt though.
$ unset DISPLAY
$ ./MuseScore-4.1.0.231061215-x86_64.AppImage -o out.pdf test.mscz
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
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.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: offscreen, xcb.
/tmp/.mount_MuseScolR9Aq/AppRun: line 26: 35023 Aborted (core dumped) "${APPDIR}/bin/mscore4portabledev" "$@"
$ ./MuseScore-4.1.0.231061215-x86_64.AppImage -platform offscreen -o out.pdf test.mscz
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
: Unknown options: p, l, a.
Then try to use the QT_QPA_PLATFORM environment variable instead, see https://doc.qt.io/qt-5/qguiapplication.html#supported-command-line-options
Then try to use the QT_QPA_PLATFORM environment variable instead, see https://doc.qt.io/qt-5/qguiapplication.html#supported-command-line-options
Ah, looks like that works, thank you!!!
$ QT_QPA_PLATFORM=offscreen ./MuseScore-4.1.0.231061215-x86_64.AppImage -o out.pdf test.mscz
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
Regarding the command line option: what you say is true, the problem is that MuseScore does not know which arguments are for Qt and which not. This is a relatively recent regression.
Before, it worked correctly because we first instantiated QApplication, which removes Qt-related arguments from argv and argc.
But since recently, we need to parse the arguments ourselves before instantiating QApplication, because based on the arguments we need to instantiate either QApplication or QCoreApplication (namely in GUI mode versus command line mode).
I don't see any better solution than looking at Qt's source code to see which arguments are handled by Qt, and skip those when parsing the arguments ourselves.
The supported commandline options are listed in https://doc.qt.io/qt-5/qguiapplication.html#supported-command-line-options
@cbjeukendrup what is the status on this issue?
I have a fix for the core of the problem of this issue, but due to a general problem with command line arguments, it is still not completely working. So let's keep this open until that general problem gets fixed, so that my fix for this issue is unblocked.
Should work after # 17510
@j-tai Can you try this build please https://github.com/musescore/MuseScore/actions/runs/4925941141 ? (or the next master nightly)
Thanks!
Should work after # 17510
@j-tai Can you try this build please https://github.com/musescore/MuseScore/actions/runs/4925941141 ? (or the next master nightly)
Thanks!
With that build, the -platform
option gives a different error. It still tries to open the display, even though I passed -display offscreen
.
$ unset DISPLAY
$ ./MuseScore-4.1.0.231291258-x86_64.AppImage -platform offscreen -v
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
(mscore4portabledev:14632): Gtk-WARNING **: 19:50:40.797: cannot open display:
$ QT_QPA_PLATFORM=offscreen ./MuseScore-4.1.0.231291258-x86_64.AppImage -v
/usr/lib/x86_64-linux-gnu/pipewire-0.3/jack/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
MuseScore4Development 4.1.0-dev
What is the status of this issue? Would like to be able to go headless in Windows, or is that impossible?
As far as I know this issue was only about Ubuntu, so on Windows it should work anyway. I'm not sure what's the status on Ubuntu; there has been quite a number of attempts to fix this, but based on the latest comment apparently still something is wrong.
As far as I know this issue was only about Ubuntu, so on Windows it should work anyway. I'm not sure what's the status on Ubuntu; there has been quite a number of attempts to fix this, but based on the latest comment apparently still something is wrong.
Right now, you can set the environment variable QT_QPA_PLATFORM=offscreen
to run it headless.
Previously, you could also pass -platform offscreen
to run it headless, but that no longer works in MuseScore 4.
If I run it on windows with the -platform offscreen option I get the following:
This application failed to start because no Qt platform plugin could be initialized. Reinstalling may fix this problem. Available platform plugins are: windows.
I investigated a bit and it turns out that a change from our side is needed to package the qoffscreen
plugin with MuseScore. I've made that change here: #19726
You can try it out by following the steps at https://github.com/musescore/MuseScore/wiki/Downloading-and-running-test-builds#downloading-builds-from-pull-requests.
I investigated a bit and it turns out that a change from our side is needed to package the
qoffscreen
plugin with MuseScore. I've made that change here: #19726 You can try it out by following the steps at https://github.com/musescore/MuseScore/wiki/Downloading-and-running-test-builds#downloading-builds-from-pull-requests.
I got a new error message: This application failed to start because no Qt platform plugin could be initialized. Reinstalling may fix this problem. Available platform plugins are: offscreen, windows. (so it does now see offscreen as available plugin, but the error persists)
EDIT: Made a mistake in the commandline, seems to work!
EDIT: Made a mistake in the commandline, seems to work!
In that case I'll merge that PR, so that the fix will be included in 4.2!
For MuseScore 3.6 in AppImage, I also couldn't run headless mode on Debian 12, same happened with the -platform offscreen
option, any thoughts? thanks!
$ sudo apt install fuse
$ wget https://cdn.jsdelivr.net/musescore/v3.6.2/MuseScore-3.6.2.548021370-x86_64.AppImage
$ chmod u+x MuseScore-3.6.2.548021370-x86_64.AppImage
$ QT_QPA_PLATFORM=offscreen ./MuseScore-3.6.2.548021370-x86_64.AppImage
/lib/x86_64-linux-gnu/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
This application failed to start because it could not find or load the Qt platform plugin "offscreen"
in "".
Available platform plugins are: xcb.
Reinstalling the application may fix this problem.
/tmp/.mount_MuseScykWLI8/AppRun: line 26: 495523 Aborted "${APPDIR}/bin/mscore-portable" "$@"
Workaround found: https://medium.com/@dinukadesilva/how-to-use-musescore-as-a-headless-command-line-tool-c3f2f0a6f224
for V3.6 or 4.2 under Linux, using xvfb instead of setting QT_QPA_PLATFORM, works like magic!
$ Xvfb -ac :99 -screen 0 1280x1024x16 &
$ export DISPLAY=:99
$ ./MuseScore-3.6.2.548021370-x86_64.AppImage -v
/lib/x86_64-linux-gnu/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
MuseScore3 3.6.2
$ ./MuseScore-4.2.1.240230938-x86_64.AppImage -v
/lib/x86_64-linux-gnu/libjack.so.0
/lib/x86_64-linux-gnu/libnss3.so
MuseScore4 4.2.1