8000 Merge pull request #18 from pygame-web/pc-vs-web-import · pygame-web/pygame-web.github.io@401728d · GitHub
[go: up one dir, main page]

Skip to content

Commit 401728d

Browse files
authored
Merge pull request #18 from pygame-web/pc-vs-web-import
third-party module for PC, but not web
2 parents 94ec592 + ab31161 commit 401728d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

wiki/pygbag/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ Make sure you're not pulling assets from outside your folder, like this!
126126
- [List of available wheels](/wiki/pkg/)
127127
- [requesting modules](https://github.com/pygame-web/pkg-porting-wasm/issues)
128128

129+
If you need to import a third-party module for PC, but not for web, use importlib. For example:
130+
```py
131+
# succeeds
132+
if sys.platform != "emscripten":
133+
import importlib
134+
importlib.import_module("copykitten")
135+
```
136+
The following will NOT work:
137+
```py
138+
# fails
139+
if sys.platform != "emscripten":
140+
import copykitten
141+
```
142+
The import is detected by pygbag and assumes you will import it at some point in the future. `http://localhost:8000/` will likely reveal a `ModuleNotFoundError`.
143+
129144
#### Complex Packages
130145
When importing complex packages (for example, numpy or matplotlib), you must put their import statements at top of `main.py`. You should also add a metadata header as specified by [PEP 723](https://peps.python.org/pep-0723/), for example:
131146
```

0 commit comments

Comments
 (0)
0