diff --git a/docs/usage/faq.md b/docs/usage/faq.md index e6977396b..f3b9e257e 100644 --- a/docs/usage/faq.md +++ b/docs/usage/faq.md @@ -110,7 +110,18 @@ my_namespace.get("z"); // ==> 4 ## How to detect that code is run with Pyodide? -**At run time**, you can detect that a code is running with Pyodide using, +**At run time**, you can check if Python is built with Emscripten (which is the +case for Pyodide) with, + +```py +import sys + +if sys.platform == 'emscripten': + # running in Pyodide or other Emscripten based build +``` + +To detect that a code is running with Pyodide specifically, you can check +for the loaded `pyodide` module, ```py import sys @@ -119,16 +130,6 @@ if "pyodide" in sys.modules: # running in Pyodide ``` -More generally you can detect Python built with Emscripten (which includes -Pyodide) with, - -```py -import platform - -if platform.system() == 'Emscripten': - # running in Pyodide or other Emscripten based build -``` - This however will not work at build time (i.e. in a `setup.py`) due to the way the Pyodide build system works. It first compiles packages with the host compiler (e.g. gcc) and then re-runs the compilation commands with emsdk. So the `setup.py` is