2019-06-22 00:25:44 +00:00
**[What is Pyodide?](#what-is-pyodide)** |
**[Try Pyodide](#try-pyodide-no-installation-needed)** |
**[Getting Started](#getting-started)** |
**[Contributing](#contributing)** |
**[License](#license)**
# [Pyodide](https://github.com/iodide-project/pyodide)
2018-02-24 17:52:47 +00:00
2018-11-07 21:15:43 +00:00
2018-06-05 01:11:32 +00:00
[![Build Status ](https://circleci.com/gh/iodide-project/pyodide.png )](https://circleci.com/gh/iodide-project/pyodide)
2019-10-21 14:39:17 +00:00
[![Documentation Status ](https://readthedocs.org/projects/pyodide/badge/?version=latest )](https://pyodide.readthedocs.io/?badge=latest)
2018-03-30 18:10:03 +00:00
2018-06-07 19:50:53 +00:00
The Python scientific stack, compiled to WebAssembly.
2019-06-22 00:25:44 +00:00
[**Try Pyodide and Iodide in your browser** ](https://alpha.iodide.io/notebooks/300/ )
## What is Pyodide?
**Pyodide** brings the Python runtime to the browser via WebAssembly, along with the Python scientific stack including NumPy, Pandas, Matplotlib, parts of SciPy, and NetworkX. The [`packages` directory ](https://github.com/iodide-project/pyodide/tree/master/packages ) lists over 35 packages which are currently available.
2018-02-23 19:34:33 +00:00
2019-06-22 00:25:44 +00:00
**Pyodide** provides transparent conversion of objects between Javascript and Python.
When used inside a browser, Python has full access to the Web APIs.
2018-06-22 18:54:59 +00:00
2019-06-22 00:25:44 +00:00
While closely related to the [iodide project ](https://iodide.io ), a tool for *literate scientific computing and communication for the web* , Pyodide goes beyond running in a notebook environment. To maximize the flexibility of the modern web, **Pyodide** may
be used standalone in any context where you want to **run Python inside a web
browser**.
## Try Pyodide (no installation needed)
For more information, try [the demo ](https://alpha.iodide.io/notebooks/300/ ) and look through the
2019-06-22 22:28:48 +00:00
[documentation ](https://pyodide.readthedocs.io/ ).
2018-06-07 19:43:04 +00:00
2019-06-22 00:25:44 +00:00
## Getting Started
Pyodide offers three different ways to get started depending on your needs and technical resources.
These include:
2019-05-31 20:02:51 +00:00
2019-06-22 00:25:44 +00:00
- [Download a pre-built version ](#download-a-pre-built-version ) (the quickest way to get started)
- [Build Pyodide from source ](#building-from-source ) (this method requires installing prerequistes and using `make` . Primarily for Linux users who want to experiment or contribute back to the project.)
- [Use a Docker image ](#using-docker ) (recommended for Windows and macOS users and for Linux users who prefer a Debian-based Docker image on Docker Hub with the dependencies
already installed)
2019-05-31 20:02:51 +00:00
2019-06-22 00:25:44 +00:00
### Download a pre-built version
Pre-built versions of Pyodide may be downloaded from
this repository's [releases page ](https://github.com/iodide-project/pyodide/releases/ ).
### Building from source
2018-02-23 19:34:33 +00:00
2019-10-18 16:18:26 +00:00
Building is easiest on Linux and relatively straightforward on Mac. For
Windows, we currently recommend using the Docker image (described below) to
build Pyodide.
2018-02-23 19:34:33 +00:00
2019-06-22 22:22:39 +00:00
Make sure the prerequisites for [emsdk ](https://github.com/emscripten-core/emsdk ) are
2018-06-21 15:19:34 +00:00
installed. Pyodide will build a custom, patched version of emsdk, so there is no
need to build it yourself prior.
2018-02-23 19:34:33 +00:00
2018-06-19 14:56:17 +00:00
Additional build prerequisites are:
2018-06-21 15:19:34 +00:00
- A working native compiler toolchain, enough to build CPython.
2018-07-18 13:26:18 +00:00
- A native Python 3.7 to run the build scripts.
2018-06-21 15:19:34 +00:00
- PyYAML
2019-06-22 22:22:39 +00:00
- [lessc ](http://lesscss.org/ ) to compile less to css.
2018-06-19 14:56:17 +00:00
- [uglifyjs ](https://github.com/mishoo/UglifyJS ) to minify Javascript builds.
2019-11-19 16:11:46 +00:00
- gfortran (GNU Fortran 95 compiler)
- [f2c ](http://www.netlib.org/f2c/ )
- [ccache ](https://ccache.samba.org ) (optional) *highly* recommended for much faster rebuilds.
2018-04-26 15:04:28 +00:00
2019-10-18 16:18:26 +00:00
On Mac, you will also need:
- [Homebrew ](https://brew.sh/ ) for installing dependencies
- System libraries in the root directory (`sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /` should do it, see https://github.com/pyenv/pyenv/issues/1219#issuecomment-428305417)
- coreutils for md5sum and other essential Unix utilities (`brew install coreutils`)
- openssl (`brew install openssl`)
- gfortran (`brew cask install gfortran`)
- f2c: Install wget (`brew install wget`), and then run the buildf2c script from the root directory (`sudo ./tools/buildf2c`)
2019-06-22 00:25:44 +00:00
#### Build using `make`
2018-07-24 15:18:01 +00:00
2019-06-22 00:25:44 +00:00
After installing the build prerequisites, run from the command line:
2018-03-30 14:51:13 +00:00
2019-06-22 00:25:44 +00:00
```bash
make
```
### Using Docker
2018-10-08 19:33:33 +00:00
We provide a Debian-based Docker image on Docker Hub with the dependencies
2019-10-18 16:18:26 +00:00
already installed to make it easier to build Pyodide. Note that building from
the Docker image is *very* slow on Mac, building on the host machine is
preferred if at all possible.
2018-10-08 19:33:33 +00:00
1. Install Docker
2. From a git checkout of Pyodide, run `./run_docker`
2019-04-24 15:09:17 +00:00
3. Run `make` to build.
2018-10-08 19:33:33 +00:00
2019-05-16 14:03:18 +00:00
If running ``make`` deterministically stops at one point in each subsequent try, increasing
2019-05-31 20:02:51 +00:00
the maximum RAM usage available to the docker container might help [This is different
from the physical RAM capacity inside the system]. Ideally, at least 3 GB of RAM
should be available to the docker container to build `pyodide` smoothly. These settings can
2019-05-16 14:03:18 +00:00
be changed via Docker Preferences [See [here ](https://stackoverflow.com/questions/44533319/how-to-assign-more-memory-to-docker-container )].
2018-10-08 19:33:33 +00:00
You can edit the files in your source checkout on your host machine, and then
repeatedly run `make` inside the Docker environment to test your changes.
2019-06-22 00:25:44 +00:00
## Contributing
Please view the [CONTRIBUTING ](CONTRIBUTING.md ) document for tips on filing
issues, making changes, and submitting pull requests. The following sections
describe how to run tests, run Pyodide benchmarks, and lint the source code.
### Testing
2018-03-30 14:51:13 +00:00
2018-06-21 15:19:34 +00:00
Install the following dependencies into the default Python installation:
2018-03-30 14:51:13 +00:00
2019-06-22 00:25:44 +00:00
```bash
pip install pytest selenium pytest-instafail
```
2018-03-30 14:51:13 +00:00
2018-07-26 09:45:00 +00:00
Install [geckodriver ](https://github.com/mozilla/geckodriver/releases ) and
2019-06-22 00:25:44 +00:00
[chromedriver ](https://sites.google.com/a/chromium.org/chromedriver/downloads )
and check that they are in your `PATH` .
### Automated testing
To run the pytest suite of tests, type on the command line:
```bash
pytest test/ packages/
```
### Manual interactive testing
To run manual interactive tests, a docker environment and a webserver will be
used.
1. Bind port 8000 for testing. To automatically bind port 8000 of the docker
environment and the host system, run: `./run_docker`
2018-03-30 14:51:13 +00:00
2019-06-22 00:25:44 +00:00
2. Now, this can be used to test the `pyodide` builds running within the
docker environment using external browser programs on the host system. To do
this, run: `./bin/pyodide serve`
2018-04-11 14:17:02 +00:00
2019-06-22 00:25:44 +00:00
3. This serves the ``build`` directory of the ``pyodide`` project on port 8000.
* To serve a different directory, use the ``--build_dir`` argument followed
by the path of the directory.
* To serve on a different port, use the ``--port`` argument followed by the
desired port number. Make sure that the port passed in ``--port`` argument
is same as the one defined as ``DOCKER_PORT`` in the ``run_docker`` script.
2018-12-11 07:56:51 +00:00
2019-06-22 00:25:44 +00:00
4. Once the webserver is running, simple interactive testing can be run by
visiting this URL:
[http://localhost:8000/console.html ](http://localhost:8000/console.html )
2018-12-11 07:56:51 +00:00
2019-06-22 00:25:44 +00:00
### Benchmarking
2018-12-11 07:56:51 +00:00
2019-06-22 00:25:44 +00:00
To run common benchmarks to understand Pyodide's performance, begin by
installing the same prerequisites as for testing. Then run:
2018-12-11 07:56:51 +00:00
2019-06-22 00:25:44 +00:00
```bash
make benchmark
```
2018-12-11 07:56:51 +00:00
2019-06-22 00:25:44 +00:00
### Linting
2018-12-11 07:56:51 +00:00
2019-06-22 00:25:44 +00:00
Python is linted with `flake8` . C and Javascript are linted with
`clang-format` .
2019-03-15 16:51:22 +00:00
2019-06-22 00:25:44 +00:00
To lint the code, run:
2018-04-11 14:17:02 +00:00
2019-06-22 00:25:44 +00:00
```bash
make lint
```
2018-04-11 14:17:02 +00:00
2019-06-22 00:25:44 +00:00
## License
2018-06-14 18:19:08 +00:00
2019-06-22 00:25:44 +00:00
Pyodide uses the Mozilla Public License Version 2.0. See the
[LICENSE file ](LICENSE ) for more details.
2018-06-14 18:19:08 +00:00
2019-06-22 00:25:44 +00:00
---
2018-06-14 18:19:08 +00:00
2019-06-22 00:25:44 +00:00
**[What is Pyodide?](#what-is-pyodide)** |
2019-07-07 08:45:57 +00:00
**[Try Pyodide](#try-pyodide-no-installation-needed)** |
2019-06-22 00:25:44 +00:00
**[Getting Started](#getting-started)** |
**[Contributing](#contributing)** |
**[License](#license)** |
**[Back to top](#pyodide)**