Registry / web-framework / pyglet

pyglet

JSON →
library2.1.16pypypi✓ verified 27d ago

Pyglet is a cross-platform windowing and multimedia library for Python, designed for developing games and other visually rich applications. It provides robust support for windowing, input event handling (keyboard, mouse, controllers), OpenGL graphics, loading various image and video formats, and playing sounds and music. Compatible with Windows, macOS, and Linux, pyglet is currently at version 2.1.14 and maintains an active development cycle with periodic updates and new releases.

pip install pyglet
INSTALL
IMPORT
SIG · PYGLET
P
pyglet
web-frameworkpythonv2.1.16
Install
2.1s avg
Import
40ms
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.1.16 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.042s · 26.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 2.1s · import 0.038s · 27MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pyglet
✓ import pyglet
Window
✓ from pyglet.window import Window
✗ import pyglet.window as window; window.Window()
While 'import pyglet' and accessing as pyglet.window.Window() works, explicit import is common for brevity.
run
✓ pyglet.app.run()
schedule_interval
✓ pyglet.clock.schedule_interval(func, interval)

This minimal example opens an 800x600 pixel window displaying 'Hello, world!' centered. It demonstrates window creation, text rendering, event handling via decorator, and starting the application loop.

import pyglet window = pyglet.window.Window(800, 600, caption='Hello Pyglet') label = pyglet.text.Label('Hello, world', font_name='Times New Roman', font_size=36, x=window.width//2, y=window.height//2, anchor_x='center', anchor_y='center') @window.event def on_draw(): window.clear() label.draw() pyglet.app.run()
Debug
Known issues
breakingPyglet 2.0 (and later) requires modern OpenGL (3.3+) context, moving away from legacy OpenGL 2.0. Applications making direct OpenGL 1.x API calls or using older shaders will need significant updates.
fix
Review and update OpenGL code to utilize modern OpenGL (3.3+) practices. Consult the 'Migrating from pyglet 1.5' guide in the official documentation.
affects: 2.0.0 and later
breakingPyglet 2.1 introduced minor breaking changes to arguments for text, UI, and game controller handling. Locations/names for some features, data types, and math classes (e.g., `pyglet.math.Mat3` and `Mat4` now accept direct arguments instead of an iterable) also changed. The `pyglet.options` module is now accessed as a `pyglet.options` attribute.
fix
Refer to the 'Migrating from pyglet 2.0' guide in the official documentation for specific changes and updated API usage.
affects: 2.1.0 and later
gotchaTo play a wide range of compressed audio (e.g., MP3, OGG/Vorbis, WMA) and video formats (e.g., MPEG2, H.264), FFmpeg must be installed separately on your system. Without it, only basic formats (like WAV, PNG, BMP) are supported.
fix
Install FFmpeg on your operating system (e.g., via a package manager like `apt`, `brew`, or by downloading binaries) if you need to play advanced media formats.
affects: All versions
gotchaWhen using `pyglet.clock.schedule_interval()` to schedule a function to run periodically, the scheduled function MUST accept a `dt` (delta time) parameter as its first argument, even if the value is not used within the function.
fix
Ensure your scheduled function signature includes `dt`, e.g., `def update(dt): ...`.
affects: All versions
gotchaForgetting to call `window.clear()` at the beginning of your `on_draw` event handler will result in drawing artifacts from previous frames, as the buffer is not explicitly cleared.
fix
Always include `window.clear()` as the first line within your `on_draw` function.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pyglet'
The pyglet library is not installed in the Python environment being used, or the Python interpreter cannot find the installed package.
fix
Ensure pyglet is installed correctly for your Python environment: `pip install pyglet` (or `pip3 install pyglet` for Python 3 specific installations). If using a virtual environment or IDE, ensure it's activated and configured to use the correct Python interpreter where pyglet is installed.
AttributeError: module 'pyglet' has no attribute 'window' (or 'text', 'gl', 'media', 'load')
This typically happens when your Python script file is named `pyglet.py` (or `window.py`, `gl.py`, etc.), causing Python to import your local script instead of the actual pyglet library. It can also occur if attempting to access attributes or functions that have been moved or deprecated in newer pyglet versions without importing the specific submodule, e.g., `pyglet.window.Window()` instead of `from pyglet import window; window.Window()` or `from pyglet.window import Window; Window()`. Or for `pyglet.load` instead of `pyglet.resource.image()` for images or `pyglet.media.load()` for media.
fix
Rename your Python script file to something other than `pyglet.py` (or any other pyglet module name like `window.py`, `gl.py`). For API changes, consult the pyglet documentation for the version you are using (e.g., `pyglet.window.Window` for creating a window, `pyglet.resource.image` for loading images, `pyglet.media.load` for loading audio/video).
ImportError: Library "GL" not found
pyglet relies on OpenGL (GL) and GLU libraries being present on your system. This error indicates that these underlying graphics libraries are missing or cannot be found by pyglet, often encountered on Linux systems or in Docker containers without proper graphics library installations.
fix
Install the necessary OpenGL development libraries for your operating system. For Debian/Ubuntu-based systems, this often involves `sudo apt-get install libgl1-mesa-dev libglu1-mesa-dev freeglut3-dev`. For other systems, refer to their package managers for OpenGL development packages.
Pyglet window appears briefly and closes / Window not responding / Program exits without showing window
The pyglet event loop, `pyglet.app.run()`, was not called or was called incorrectly. This function is essential for starting the application's event processing, keeping the window open, and making it responsive to user input and drawing events. Without it, the program will execute and terminate, closing the window immediately, or the window will become unresponsive.
fix
Ensure `pyglet.app.run()` is called at the end of your main script after setting up your window and event handlers. This starts the main event loop. For example: `import pyglet; from pyglet.window import Window; window = Window(); @window.event def on_draw(): pass; pyglet.app.run()`.
ImportError: cannot import name 'GL_LIGHTING' from 'pyglet.gl'
This error frequently arises when using code written for older versions of pyglet (specifically `pyglet 1.x`) with a newer `pyglet 2.x` installation. Many OpenGL constants and functions were reorganized or deprecated in `pyglet 2.x` to align with modern OpenGL practices.
fix
If using a codebase designed for `pyglet 1.x`, downgrade your pyglet installation to a compatible version (e.g., `pip install pyglet==1.5.27`). Alternatively, update your code to use the `pyglet 2.x` API, which might involve importing constants from different submodules or using more modern OpenGL approaches (e.g., shaders instead of immediate mode functions like `GL_LIGHTING`).
Upgrade
Version history
2.1.16latest on PyPI · released Aug 1, 2026
Audit
Dependencies
FFmpegoptionalOptional dependency for playing a wide variety of compressed audio (MP3, OGG/Vorbis, WMA) and video (MPEG2, H.264, H.265, WMV, Xvid) formats. Built-in support exists for basic formats (wav, png, bmp) without FFmpeg.
Agent activity
10 hits · last 30 days
node
8
Resources
pyglet — pip install pyglet · libregistry