Closed ProarchwasTaken closed 1 year ago
Sorry but import numpy
work for me in the PYGBAG TEST REPL
We will need more information to help you, eg publish or zip your game with assets somewhere or make a small repro case.
Make sure you are using pygbag 0.7.2 and that you removed build folder in the game folder at least once after problem arose and retry to show us the debug console ( http://localhost:8000?-i or http://localhost:8000#debug ).
I updated to the latest version of pygbag and it still stops when trying to import numpy. I did manage to save the debug console.
Please wait ...
807: DEV MODE ON ['http://localhost:8000/archives/repo/']
378: asyncio.run(coro=<coroutine object import_site at 0xba91b0>)
849: fopen: fetching "http://localhost:8000/archives/repo/index.json" with flags={'redirect': 'follow', 'credentials': 'omit'}
1601: running __file__='/data/data/org.python/assets/main.py'
1020: import scan filename='<stdin>' len(code)=5082 ['pygame.base']
849: fopen: fetching "http://localhost:8000/archives/repo/repodata.json" with flags={'redirect': 'follow', 'credentials': 'omit'}
referenced packages : 184
1264: https://pygame-web.github.io/archives/repo/ REMAPPED TO http://localhost:8000/archives/repo/
installing pygame.base
1202: want='pygame.base' found : True
pkg : http://localhost:8000/archives/repo/pkg/pygame_static-1.0-cp311-cp311-wasm32_mvp_emscripten.whl
|XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX| 100.0%
88: pygame.base requires patch
pygame-ce 2.4.0.dev1 (SDL 2.24.2, Python 3.11.4)
https://github.com/pygame-web/pygbag/issues/16
applying: use aio green thread for pygame.time.set_timer
sys._emscripten_info(emscripten_version=(3, 1, 34), runtime='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36', pthreads=False, shared_memory=False)
646: starting shell
996: 213 lines queued for async eval
Loading tld_lorenzo from tld_lorenzo.apk
Pygbag Version : 0.7.2
Template Version : 0.7.3
Python : 3.11
CDN URL : http://localhost:8000//archives/0.7/
Screen : {{cookiecutter.width}}x{{cookiecutter.height}}
Title : tld_lorenzo
Folder : tld_lorenzo
Authors : pgw
SPDX-License-Identifier: cookiecutter.spdx
1690: __file__='/data/data/org.python/assets/main.py' done : now trying remote sources
1745 local=None source='' is_py=False hint='main.py'
404: embed= or sys.argv=['debug']
642: starting EventTarget in a few seconds
Python 3.11.4 (main, Aug 20 2023, 23:58:07) [Clang 17.0.0 (https://github.com/llvm/llvm-project a031f72187ce495b9faa4ccf99b1 on emscripten
Type "help", "copyright", "credits" or "license" for more information.
>>> 284: assets found : 0
341: EventTarget delayed by loader
/data/data/org.python/assets/site-packages/pygame/sysfont.py:234: UserWarning: no fc_cache font cache file at /data/data/tld_lorenzo/assets/fc_cache
warnings.warn(f"no fc_cache font cache file at {fc_cache}")
* Waiting for media user engagement : please click/touch page *
1020: import scan filename='<stdin>' len(code)=4266 ['settings', 'glob', 'scenes']
1063: repo['-CDN-']='http://localhost:8000/archives/repo/' does not provide want='settings'
1063: repo['-CDN-']='http://localhost:8000/archives/repo/' does not provide want='glob'
1063: repo['-CDN-']='http://localhost:8000/archives/repo/' does not provide want='scenes'
1291: {req=} in {cls.ignore=} or sys.modules
646: starting shell
996: 125 lines queued for async eval
going interactive
643: TODO detect input/print to select repl debug
What's really strange to me is that it didn't raise any errors at all! Pygbag simply decided to "stop" when it tries to import NumPy for the first time.
@ProarchwasTaken i would need a screenshot of last third of the javascript console ( ctrl+shift+i ) on a brave/chromium/chrome browser.
Okay, I got the Console Screenshots.
@pmp-p I think I found a solution to the issue I'm facing. After asking on reddit , I've found that I have to import the numpy module as soon as possible just after importing pygame. You see, my game is a multi-file project and I never bothered to import numpy into the main file, not in files I needed to use it in.
It fixed the "Numpy" Issue but it still didn't work as I realized that there might be more modules that might conflict with pygbag. I had to do a couple hours of debugging just to find out what imported modules are causing pygbag to fail. After searching, I found out the culprits are the Numba and Statistic modules. After I removed them from the project, my game starts to working perfectly fine in the browser.
Personally, I think the big issue is: Pygbag doesn't raise an error for situations like this! Instead, pygbag just silently stops, giving absolutely zero information of what's wrong. If it wasn't for that one guy on reddit, I wouldn't have figured it out.
For more clarity I would like to link to the reddit comment that helped me figure it out: https://www.reddit.com/r/pygame/comments/162qefm/comment/jxzo8wl/?context=3
numpy is quite a special case as it has tons of wasm modules that confuse/crash python when imported too late and that's why it is mentionned here https://pygame-web.github.io/#coding
mandatory when importing packages : put the “import “ at top of main.py ( eg import numpy, matplotlib )
maybe enhance the wording ? suggestion or - better - PR welcomed
I was trying to get my game to work in the web browser using Pygbag but all it shows is just a black screen. After some debugging, I've found out that Pygbag stops working when importing the NumPy module for the first time.
Is this anything I could do, or is this just an issue with pygbag? I use pygame_ce 2.3.0 and numpy 1.24.4.