pygame-web/pygbag

"TypeError: 'WindowsPath' object is not subscriptable" HTML build does not working.

Closed this issue · 4 comments

I tried to build project as html.

pygbag --html main.py

but it didn't work with this error:

Traceback (most recent call last):
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\Scripts\pygbag.exe\__main__.py", line 7, in <module>
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\site-packages\pygbag\app.py", line 483, in main
    asyncio.run(main_run(app_folder, mainscript))
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\asyncio\base_events.py", line 647, in run_until_complete
    return future.result()
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\site-packages\pygbag\app.py", line 340, in main_run
    await pack.archive(f"{app_name}.apk", app_folder, build_dir)
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\site-packages\pygbag\pack.py", line 102, in archive
    html_embed(target_folder, packlist, apkname[:-4] + ".html")
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\site-packages\pygbag\html_embed.py", line 127, in html_embed
    dump_fs(html, target_folder, packlist)
  File "C:\Users\petty\AppData\Local\Programs\Python\Python39\lib\site-packages\pygbag\html_embed.py", line 37, in dump_fs
    vfs_name = topack[1:].replace("-pygbag.", ".")
TypeError: 'WindowsPath' object is not subscriptable

My Env:

  • Windows11 22H2
  • Python==3.9.13
  • pygbag==0.7.2
pmp-p commented

--html is for pygame-script - not well tested - and does not support packing a game that is not 100% web certified it:

  • need posix filepath
  • need no MP3/WAV ( and no presence of them) only ogg (use audacity to convert)
  • need no BMP ( and no presence of them)
  • no non utf-8 encoding on source filesystem ( may be a problem on non posix system )

if you could zip and upload the whole folder somewhere ( eg https://drop.infini.fr/ ), it could help to debug and add usefull error messages, thank you in advance.

if you want to publish a complex game, use --archive instead you will get a web.zip suitable for itch.io or to unpack in your webserver (prefer using an iframe).

Thank you!
I'll try archive.

--html is for pygame-script - not well tested - and does not support packing a game that is not 100% web certified it:

  • need posix filepath
  • need no MP3/WAV ( and no presence of them) only ogg (use audacity to convert)
  • need no BMP ( and no presence of them)
  • no non utf-8 encoding on source filesystem ( may be a problem on non posix system )

if you could zip and upload the whole folder somewhere ( eg https://drop.infini.fr/ ), it could help to debug and add usefull error messages, thank you in advance.

if you want to publish a complex game, use --archive instead you will get a web.zip suitable for itch.io or to unpack in your webserver (prefer using an iframe).

I have the same issue when using <Python -m pygbag --html main.py>. I have upload all files to https://drop.infini.fr/ . here is the link : https://drop.infini.fr/r/sWv5jqntaf#VrNNs5NUnlwC//IIbdneMgChT24ElK1H1hCZDKmV6BQ=

It is worth mentioning that: <Python -m pygbag main.py> can run perfectly

pmp-p commented

@songyuyx thanks but i had no problem packing your game to .html
note that "100% web certified" means no venv and no extra files lying around : ie a folder with only :

.
├── background_music.ogg
├── background.png
├── bullet.png
├── enemy_hit_sound.ogg
├── enemy_ship.png
├── explosion.png
├── gameover.jpg
├── main.py
└── player_ship.png

du -hs build/web/songyuyx.html
2.6M build/web/songyuyx.html

NB: the python runtime IS NOT encoded into the html file, so you may have trouble when behind a firewall/proxy. see #77