🚀 Get GitHub Copilot Free in VS Code!
Dismiss this update
We are happy to announce experimental support for running Python code on the Web. To try it out, install the latest pre-release version of the Experimental - Python for the Web extension from the Marketplace. This work is based on WASM in Python, which is currently in development. To learn more about how it works and the ongoing progress, you can read Compiling Python to WebAssembly (WASM).
The following prerequisites are needed to use the extension:
https://insiders.vscode.dev/
)?vscode-coi=
.The screenshot below shows the execution of a simple Python program in the browser. The program consists of two files app.py
and hello.py
stored on the local file system.
The extension comes with an integrated Python REPL. To activate it, run the command Python WASM: Start REPL.
There is support for debugging Python files on the Web and it uses the same UI as VS Code Desktop debugging. The features currently supported are:
The screenshot below shows an active debug session. The files are hosted directly on GitHub on this sample repository.
The extension uses a pre-configured Python environment based on the CPython WebAssembly builds. The build used is Python-3.11.0-wasm32-wasi-16.zip
.
You can create your own Python environment, including source wheel Python packages, following these steps:
Create a new GitHub repository.
Download a wasm-wasi-16 build from cpython-wasm-test/releases and expand it into the root of the repository.
To add source wheel packages, do the following:
site-packages
folder in the root.pip install my_package --target ./site-packages
. Note that you need to have a Python installation in your OS including pip.Commit the changes.
Change the python.wasm.runtime
setting to point to your GitHub repository. For example:
{
"python.wasm.runtime": "https://github.com/dbaeumer/python-3.11.0"
}
The Python for the Web support doesn't provide all the features available when running source code on your local machine. The major limitations in the Python interpreter are:
The work would have not been possible without the support of the Python community, who are building and maintaining the necessary WASM files of CPython.
If you run into issues while using the Python for the Web extension, you can enter issues in the vscode-python-web-wasm repository.