xvfbwrapper is a Python library for controlling X11 virtual displays with Xvfb (X virtual framebuffer). Xvfb is a display server implementing the X11 protocol that runs entirely in memory, without requiring a physical screen or input devices. This enables GUI applications designed for X Windows to execute on headless systems, which is particularly useful for automated testing. The current version is 0.2.23, and it is actively maintained.
pip install xvfbwrapperVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the recommended way to use `xvfbwrapper` with a context manager. It automatically starts and stops the Xvfb display, ensuring proper cleanup. The `DISPLAY` environment variable is set for child processes within the `with` block. Note that the system-level `Xvfb` package must be installed first.
Install Xvfb on your operating system (e.g., `sudo apt-get install xvfb` on Debian/Ubuntu, `yum install xorg-x11-server-Xvfb` on Red Hat/CentOS).
Adopt the context manager pattern: `with Xvfb(): # your code` or `xvfb = Xvfb(); xvfb.start(); try: # your code finally: xvfb.stop()`.
Set `set_xdg_session_type=True` when initializing `Xvfb` (e.g., `Xvfb(set_xdg_session_type=True)`) or explicitly set `os.environ["XDG_SESSION_TYPE"] = "x11"` before launching your GUI application.
Upgrade to `xvfbwrapper` version 0.2.20 or newer. If upgrading isn't possible, ensure the `DISPLAY` environment variable is either unset or contains a valid display string, not an empty one.
Install the package using pip: `pip install xvfbwrapper`
Use the correct import statement: `from xvfbwrapper import Xvfb`
Install 'Xvfb' using your system's package manager (e.g., `sudo apt-get install xvfb` on Debian/Ubuntu, `sudo yum install xorg-x11-server-Xvfb` on RHEL/CentOS).
Increase the timeout when initializing Xvfb (e.g., `Xvfb(timeout=30)`) or investigate system-level issues preventing Xvfb from starting correctly, such as available display numbers or hardware resources.