PyBoy

Baekalfen活跃维护

用 Python 写的 Game Boy 模拟器,能跑原版卡带游戏,还提供库接口方便在 Python 里做游戏逻辑测试和 AI 实验。

Game Boy emulator written in Python

v2.9.0发布于 2026-10-30 17:22 UTC5,236star +1 / 7 天542fork同步于 2026-11-10 11:36 UTC

怎么上手

由 README 提炼,执行前请确认
pip install pyboy
pyboy game_rom.gb
硬件要求按 README 说明

README 未说明具体硬件要求;只提到可在 8 核机器上并行跑多个实例

下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

用 Python 写的 Game Boy 模拟器,方便做强化学习训练和脚本自动化

用 Python 写的 Game Boy 模拟器,能跑原版卡带游戏,还提供库接口方便在 Python 里做游戏逻辑测试和 AI 实验。

核心能力

  • 提供 PyBoy API,可读取内存、模拟按键、截取屏幕
  • 支持 fast_mode 降低模拟精度换取速度
  • 可跳过渲染帧,只跑游戏逻辑提升吞吐
  • 支持多实例并行跑多个模拟器
  • 内置回放(rewind)插件可倒回游戏进度

容易踩的坑

需要自备 Game Boy ROM 文件,项目不附带游戏;fast_mode 会牺牲模拟精度;性能数据依赖具体游戏,实际速度需自行测试

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v2.9.0
  1. v2.9.0最新正式版2026-10-30 · 2026-10-30 17:22 UTC

    Emulation:

    • New dot-based PPU renderer with cycle-accurate mid-scanline behavior • Passes all Daid, Bully, Acid Hell, CasualPokePlayer and mealybug tests • STOP now halts the DMG system clock • Frame limiter timing matched to the Game Boy clock • Fix CPU prefetch bug

    Performance:

    • Opt-in fast mode (fast_mode=True) for faster, less accurate emulation • Fast paths for I/O, HRAM, cartridge RAM/RTC and timer scheduling • Batched dot rendering and inlined hot paths in CPU and LCD • Profile-guided build tooling (make pgo) • CUDA and Metal screen rendering (optional Torch backends)

    Other:

    • Fix GLFW window close • Exceptions in post-tick plugins now bubble up

  2. v2.8.12026-10-07 · 2026-10-07 14:58 UTC
    查看更新说明
    • Fix performance bug
  3. v2.8.02026-10-07 · 2026-10-07 10:23 UTC
    查看更新说明

    Features:

    • GB Printer support
    • Super Game Boy borders (not full SGB mode)
    • MP4 screen recording
    • MBC30 support
    • MBC1 multicart support
    • MBC5 rumble support
    • Link Cable support using shared memory (Pokemon Link Cable example)
    • New Sphinx docs
    • Wiki moved to Sphinx

    Emulation improvements:

    • All Mooneye tests (except CGB revision checks)
    • All Samesuite tests (except CGB revision checks)
    • All Blargg tests (except wont-fix oam-bug)
    • Improvements include changes to: OAM, DMA, PPU/LCD, APU, interrupt, CPU-timing, etc.

    Wrappers:

    • Super Mario Deluxe
    • Greatly improve Pokemon Red/Blue
    • 2048 (homebrew)
    • Pandora blocks (homebrew)

    Development:

    • CGB colors in debug view
    • ROM tests to mark failures with xfail
    • Debug view for game area with object annotations
    • Run all pyboy/, tests/ and docs/ in compiled mode
    • Major refactor of testing. Many tests converted from screenshots to text
    • Using official reference images for testing
    • A LOT of new test ROMs
  4. v2.7.12026-05-05 · 2026-05-05 14:46 UTC
    查看更新说明

    What's Changed

    New Contributors

    Full Changelog: https://github.com/Baekalfen/PyBoy/compare/v2.7.0...v2.7.1

  5. v2.7.02026-01-24 · 2026-01-24 08:31 UTC
    查看更新说明
    • Improve sound emulation
    • Add GLFW window type

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Getting Started

    The instructions are simple:

    $ pip install pyboy
    

    For platform-specific instructions, see the installation guide.

    Now you're ready! Either use PyBoy directly from the terminal

    $ pyboy game_rom.gb
    

    Or use it in your Python scripts:

    from pyboy import PyBoy
    pyboy = PyBoy('game_rom.gb')
    while pyboy.tick():
        pass
    pyboy.stop()
    

    The API

    If you are looking to make a bot or AI, then these resources are a good place to start:

    When the emulator is running, you can easily access PyBoy's API:

    pyboy.set_emulation_speed(0) # No speed limit
    pyboy.button('down')
    pyboy.button('a')
    pyboy.tick() # Process at least one frame to let the game register the input
    value_of_interest = pyboy.memory[0xC345]
    
    pil_image = pyboy.screen.image
    pil_image.save('screenshot.png')
    

    The documentation homepage shows how to interface with PyBoy from your own project.

    Performance

    Performance is a priority for PyBoy, to make your AI training and scripts as fast as possible. Use the fast-mode to allow less accurate emulation, in exchange for performance: p = PyBoy(..., fast_mode=True).

    The easiest way to improve your performance, is to skip rendering of unnecessary frames. If you know your character takes X frames to move, or the game doesn't take input every frame, you can skip those to potentially triple your performance. All game logic etc. will still process.

    Here is a simple comparison of rendering every frame, rendering every 25th frame, and not rendering any frames (higher is better). See pyboy.tick for how it works. Your performance will depend on the game.

    for _ in range(target):
        pyboy.tick()
    
    
    for _ in range(target//25):
        pyboy.tick(25)
    
    
    pyboy.tick(target, False)
    
    

    The Game Boy was originally running at 60 frames per second, so a speed-up of 100x realtime is 6,000 frames per second. And trivially from the table above, simulating 1,014 hours of gameplay can be done in 1 hour with no rendering.

    It's also recommended to be running multiple instances of PyBoy in parallel. On an 8-core machine, you could potentially do 8,112 hours of gameplay in 1 hour.

    Contributing

    For development setup, testing, and pull request guidance, see the Contributing guide. You can browse open issues or discuss larger proposals on the PyBoy Discord.