CDN root used by pygbag
Github repo, and older runtimes
This software does not track usage at all, not even for statistics purpose so if you like it :
please do not forget to ⭐⭐ Star ⭐⭐ it !
Do NOT forget to read the coding section for WASM. You WILL have to change a few lines to classic python/pygame code.
-
do not use python installed from windows store, use an official python.org build you can check version installed with
py --list
command. If python/pygbag is not installed in your PATH env, use the commandpy -m pygbag
-
do not use "\" a path separator, pygbag is POSIX and use "/" instead eg open("img/my_image.png","rb) the change should not interfere and still work on recent Win32.
IMPORTANT MAC users : if you get SSL error, use the file "Install Certificates.command" in Applications/Python 3.XX
IMPORTANT Linux users: when using webusb ftdi serial emulation use sudo rmmod ftdi_sio
after plugging devices.
IMPORTANT ALL: when importing complex wheels that depend on each other, always put them in order (but numpy first) in main.py
Before packaging, adapt your code this way if you still want wav format on desktop :
if sys.platform == "emscripten":
snd = pygame.mixer.Sound("sound.ogg")
else:
snd = pygame.mixer.Sound("sound.wav") # or .WAV,.mp3,.MP3
also avoid raw format like BMP for your assets they are too big for web use. prefer PNG or JPG
There is none actually, because pygbag is not a framework it is just a friendly web version of official CPython (nothing has been changed, just some facilities added). Most desktop code will run (and will continue to run) with only a few lines changes. This is actually true for games but for applications it can be very difficult to port, even sometimes impossible.
Try to avoid relying on CPython stdlib for web operations, GUI (like tk) or I/O as it is very synchronous, platform specific and will probably stay that way.
Note about GUI: pygame-ce provides pygame_gui, Panda3D provides directgui and Harfang3D imgui => and they are all cross platform.
As alternative using pygame or pygbag supported game engines will ensure you platform independence including access to mobile ones.
basic structure of a game should be like :
test
├── img
│ ├── pygc.bmp
│ ├── pygc.png
│ └── tiger.svg
├── main.py
└── sfx
└── beep.ogg
then run pygbag test/main.py
against it, and first goes to http://localhost:8000?-i (with terminal and debugging info, for older pygbag version use http://localhost:8000#debug instead) or http://localhost:8000 (fullscreen windowed when it is running ok)
usefull additions to your .gitignore
*.wav
*.mp3
*.pyc
*.egg-info
*-pygbag.???
/build
/dist
mandatory when importing packages : put the "import " at top of main.py ( eg import numpy, matplotlib )
if using pygame-zero : put #!pgzrun near the top of main ( 2nd line is perfect if file already has a shebang ) Note: pgzero is mostly untested
- enter debug mode
- while working you can access simulator of web loop by replacing
import asyncio
byimport pygbag.aio as asyncio
at top of main.py and run program directly from main.py folder - TODO: android remote debugging via chromium browsers series
- TODO: universal remote debugging via irc client or websocket using pygbag.net
- pygame-script (wip!)
- REPL
- CPython testsuite (wip!)
(for testing, may not always work since they use daily/weekly devel version)
Please ! use the tag pygame-wasm for your projects hosted on Github and also add a favicon.png icon 32x32 next to your game main.py, so it is picked up by default.
( expected to be stable )
nb : code is read-only, prefer right-click then open in new window.
Python Wasm explained by core dev Christian Heimes (youtube video)
pygame tech demo PyCon DE & PyData Berlin 2022
French : Python WebAssembly at PyCon FR 2023 Pour quoi, pour qui et comment