Using Pyodide from Iodide¶
Running basic Python¶
Create a Python chunk, by inserting a line like this:
%% py import sys sys.version
Only the Python standard library and
six are available after importing
Pyodide. Other available libraries, such as
matplotlib are loaded
If you just want to use the versions of those libraries included with Pyodide, all you need to do is import and start using them:
%% py import numpy as np np.arange(10)
For most uses, that is all you need to know.
However, if you want to use your own custom package or load a package from
another provider, you’ll need to use the
pyodide.loadPackage function from a
%% js pyodide.loadPackage('https://custom.com/numpy.js')
After doing that, the numpy you import from a Python chunk will be this special version of Numpy.
Using a local build of Pyodide with Iodide¶
You may want to build a local copy of Pyodide with some changes and test it inside of Iodide.
By default, Iodide will use a copy of Pyodide deployed to Netlify. However, it
will use locally-installed copy of Pyodide if
USE_LOCAL_PYODIDE is set.
Set that environment variable in your shell:
Then follow the building and running instructions for Iodide as usual.
Next, build Pyodide using the regular instructions in
../README.md. Copy the
contents of Pyodide’s build directory to your Iodide checkout’s
mkdir $IODIDE_CHECKOUT/build/pyodide cp $PYODIDE_CHECKOUT/build/* $IODIDE_CHECKOUT/build/pyodide