8000 Packages Not Loading When Using type="py-game" · Issue #2304 · pyscript/pyscript · GitHub
[go: up one dir, main page]

Skip to content

Packages Not Loading When Using type="py-game" #2304

New issue
10000

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

Closed
3 tasks done
danyeaw opened this issue Feb 28, 2025 · 5 comments · Fixed by #2311
Closed
3 tasks done

Packages Not Loading When Using type="py-game" #2304

danyeaw opened this issue Feb 28, 2025 · 5 comments · Fixed by #2311
Labels
needs-triage Issue needs triage type: bug Something isn't working

Comments

@danyeaw
Copy link
Collaborator
danyeaw commented Feb 28, 2025

Checklist

  • I added a descriptive title
  • I searched for other issues and couldn't find a solution or duplication
  • I already searched in Google and didn't find any good information or help

What happened?

When using <script type="py-game">, packages specified in the configuration are not being installed/loaded properly, despite working correctly with <script type="py">. This appears to affect all non-standard library packages when using the PyGame integration.

What browsers are you seeing the problem on? (if applicable)

Firefox

Console info

ModuleNotFoundError: No module named 'numpy'
The module 'numpy' is included in the Pyodide distribution, but it is not installed.
You can install it by calling:
  await micropip.install("numpy") in Python, or
  await pyodide.loadPackage("numpy") in JavaScript

Additional Context

What Works / What Doesn't

  • ✅ Standard library packages work fine with both script types
  • ✅ External packages work correctly when using <script type="py">
  • ❌ External packages fail to load when using <script type="py-game">
  • ❌ The issue occurs with any external package (numpy, httpx, etc.)

Steps to Reproduce

  1. Create a simple HTML file with a PyGame script that imports an external package
  2. Configure the package in TOML: packages = ["numpy"]
  3. Use <script type="py-game" src="main.py" config="pyscript.toml"></script>
  4. Observe the error when trying to import the package

Minimal Reproducible Example

I've created a minimal example to demonstrate this issue: https://pyscript.com/@dyeaw/pygame-numpy-minimal-example/

Expected Behavior

Packages specified in the configuration should be properly installed and available for import when using type="py-game", just as they are with type="py".

Additional Information

  • PyScript Version: 2025.2.4
  • It can be reproduced in the latest Firefox and Chrome

I understand that PyGame support is experimental, but this issue makes it difficult to build applications that integrate PyGame with other packages.

@danyeaw danyeaw added needs-triage Issue needs triage type: bug Something isn't working labels Feb 28, 2025
@nasrin1748
Copy link
Contributor

I think PyGame is not Pyodide authorized(works on local file) and canvas is Pyodide authorized(works on browser).Both needs to be of same level to make it work.

@pbalcer
Copy link
pbalcer commented Mar 1, 2025

Can confirm. This affects not just packages but simple file imports as well. It seems that 'config' argument is ignored for py-game type scripts.

@nasrin1748
Copy link
Contributor

Here is the py-game working directory which is my local system working directory.

Image

Here is the canvas with pyscript which shows pyodide working directory.

Image

Both needs to be same to make it work in pyscript.

WebReflection added a commit that referenced this issue Mar 10, 2025
* Fix #2304 - Make pyimport work as expected

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
@WebReflection
Copy link
Contributor

This MR fixes this #2311 (among other things) and one could test this already via https://pyscript.com/@agiammarchi/pygame-numpy-minimal-example-copy/latest?files=main.py

@danyeaw
Copy link
Collaborator Author
danyeaw commented Mar 11, 2025

Thanks @WebReflection for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage Issue needs triage type: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
0