Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
matcha1024 opened this issue Sep 17, 2023 · 4 comments

Comments

@matcha1024
Copy link

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
Copy link
Member

pmp-p commented Sep 18, 2023

--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).

@matcha1024
Copy link
Author

Thank you!
I'll try archive.

@songyuyx
Copy link

--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
Copy link
Member

pmp-p commented Nov 16, 2023

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants