是否可以在 Gitlab CI 上 运行 X11?
Is it possible to run X11 on Gitlab CI?
我正在尝试使用 pyinstaller 将 python 游戏构建到二进制文件中。我让它工作了,但今天我改用街机而不是 pygame。我可以在本地很好地构建这个,但是当 pyinstaller 正在构建时,pyglet 抛出一个异常,说它找不到 X11 库。我在构建它之前安装了 xorg,它并没有抛出异常,只是说它无法连接到显示服务器。这是完整的回溯:
$ pyinstaller -F biogame.spec
39 INFO: PyInstaller: 4.1
39 INFO: Python: 3.8.5
50 INFO: Platform: Linux-4.19.78-coreos-x86_64-with-glibc2.29
52 INFO: UPX is not available.
54 INFO: Extending PYTHONPATH with paths
['/builds/TabulateJarl8/biogame', '/builds/TabulateJarl8/biogame']
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pyglet/__init__.py", line 337, in __getattr__
return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'Window'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pyinstaller", line 8, in <module>
sys.exit(run())
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/building/build_main.py", line 720, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/building/build_main.py", line 667, in build
exec(code, spec_namespace)
File "biogame.spec", line 8, in <module>
a = Analysis(['biogame.py'],
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/building/build_main.py", line 212, in __init__
self.hookspath += list(entry_point.load()())
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.8/dist-packages/arcade/__init__.py", line 72, in <module>
from .window_commands import close_window
File "/usr/local/lib/python3.8/dist-packages/arcade/window_commands.py", line 106, in <module>
def get_window() -> pyglet.window.Window:
File "/usr/local/lib/python3.8/dist-packages/pyglet/__init__.py", line 343, in __getattr__
__import__(import_name)
File "/usr/local/lib/python3.8/dist-packages/pyglet/window/__init__.py", line 1897, in <module>
gl._create_shadow_window()
File "/usr/local/lib/python3.8/dist-packages/pyglet/gl/__init__.py", line 206, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File "/usr/local/lib/python3.8/dist-packages/pyglet/window/xlib/__init__.py", line 173, in __init__
super(XlibWindow, self).__init__(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/pyglet/window/__init__.py", line 585, in __init__
display = pyglet.canvas.get_display()
File "/usr/local/lib/python3.8/dist-packages/pyglet/canvas/__init__.py", line 94, in get_display
return Display()
File "/usr/local/lib/python3.8/dist-packages/pyglet/canvas/xlib.py", line 123, in __init__
raise NoSuchDisplayException('Cannot connect to "%s"' % name)
pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"
我尝试了 运行 xinit
但是由于没有任何显示而出错了,我尝试了 xrandr
但也失败了,我也尝试了 export DISPLAY=:0
这没有帮助。有什么方法可以在 Gitlab CI 上获取 X11 运行 或者这是不可能的?这是我的 CI 文件中相关的部分:
ubuntubuild:
image: ubuntu:latest
stage: ubuntubuild
before_script:
- apt update
- DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends python3-pip python3-dev libjpeg-dev zlib1g-dev xorg
- python3 -m pip install pyinstaller
- python3 -m pip install -r requirements.txt
script:
- pyinstaller -F biogame.spec
artifacts:
paths:
- dist/biogame
更新 1:
我设法获得了 Xvfb 运行,但现在 pyglet 抛出了一个错误 pyglet.gl.glx_info.GLXInfoException: pyglet requires an X server with GLX
。我尝试将 Xvfb 调整为 Xvfb :1 -screen 0 1152x900x8 +extension GLX +render -noreset &
,并且尝试安装这些软件包:mesa-common-dev libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev
我终于想出了解决办法。我用 xvfb-run
安装了这些包和 运行 pyinstaller
sudo apt install xorg-dev libglu1-mesa libgl1-mesa-dev xvfb libxinerama1 libxcursor1
xvfb-run -a -s "-screen 0 1400x900x24 +extension RANDR" -- pyinstaller -F biogame.spec
我正在尝试使用 pyinstaller 将 python 游戏构建到二进制文件中。我让它工作了,但今天我改用街机而不是 pygame。我可以在本地很好地构建这个,但是当 pyinstaller 正在构建时,pyglet 抛出一个异常,说它找不到 X11 库。我在构建它之前安装了 xorg,它并没有抛出异常,只是说它无法连接到显示服务器。这是完整的回溯:
$ pyinstaller -F biogame.spec
39 INFO: PyInstaller: 4.1
39 INFO: Python: 3.8.5
50 INFO: Platform: Linux-4.19.78-coreos-x86_64-with-glibc2.29
52 INFO: UPX is not available.
54 INFO: Extending PYTHONPATH with paths
['/builds/TabulateJarl8/biogame', '/builds/TabulateJarl8/biogame']
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/pyglet/__init__.py", line 337, in __getattr__
return getattr(self._module, name)
AttributeError: 'NoneType' object has no attribute 'Window'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/pyinstaller", line 8, in <module>
sys.exit(run())
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/__main__.py", line 114, in run
run_build(pyi_config, spec_file, **vars(args))
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/__main__.py", line 65, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/building/build_main.py", line 720, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/building/build_main.py", line 667, in build
exec(code, spec_namespace)
File "biogame.spec", line 8, in <module>
a = Analysis(['biogame.py'],
File "/usr/local/lib/python3.8/dist-packages/PyInstaller/building/build_main.py", line 212, in __init__
self.hookspath += list(entry_point.load()())
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2445, in load
return self.resolve()
File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 2451, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.8/dist-packages/arcade/__init__.py", line 72, in <module>
from .window_commands import close_window
File "/usr/local/lib/python3.8/dist-packages/arcade/window_commands.py", line 106, in <module>
def get_window() -> pyglet.window.Window:
File "/usr/local/lib/python3.8/dist-packages/pyglet/__init__.py", line 343, in __getattr__
__import__(import_name)
File "/usr/local/lib/python3.8/dist-packages/pyglet/window/__init__.py", line 1897, in <module>
gl._create_shadow_window()
File "/usr/local/lib/python3.8/dist-packages/pyglet/gl/__init__.py", line 206, in _create_shadow_window
_shadow_window = Window(width=1, height=1, visible=False)
File "/usr/local/lib/python3.8/dist-packages/pyglet/window/xlib/__init__.py", line 173, in __init__
super(XlibWindow, self).__init__(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/pyglet/window/__init__.py", line 585, in __init__
display = pyglet.canvas.get_display()
File "/usr/local/lib/python3.8/dist-packages/pyglet/canvas/__init__.py", line 94, in get_display
return Display()
File "/usr/local/lib/python3.8/dist-packages/pyglet/canvas/xlib.py", line 123, in __init__
raise NoSuchDisplayException('Cannot connect to "%s"' % name)
pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"
我尝试了 运行 xinit
但是由于没有任何显示而出错了,我尝试了 xrandr
但也失败了,我也尝试了 export DISPLAY=:0
这没有帮助。有什么方法可以在 Gitlab CI 上获取 X11 运行 或者这是不可能的?这是我的 CI 文件中相关的部分:
ubuntubuild:
image: ubuntu:latest
stage: ubuntubuild
before_script:
- apt update
- DEBIAN_FRONTEND=noninteractive apt install -y --no-install-recommends python3-pip python3-dev libjpeg-dev zlib1g-dev xorg
- python3 -m pip install pyinstaller
- python3 -m pip install -r requirements.txt
script:
- pyinstaller -F biogame.spec
artifacts:
paths:
- dist/biogame
更新 1:
我设法获得了 Xvfb 运行,但现在 pyglet 抛出了一个错误 pyglet.gl.glx_info.GLXInfoException: pyglet requires an X server with GLX
。我尝试将 Xvfb 调整为 Xvfb :1 -screen 0 1152x900x8 +extension GLX +render -noreset &
,并且尝试安装这些软件包:mesa-common-dev libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev
我终于想出了解决办法。我用 xvfb-run
sudo apt install xorg-dev libglu1-mesa libgl1-mesa-dev xvfb libxinerama1 libxcursor1
xvfb-run -a -s "-screen 0 1400x900x24 +extension RANDR" -- pyinstaller -F biogame.spec