Hyper Open Edge Cloud

HowToBuildPyodide

  • Last Update:2019-02-04
  • Version:001
  • Language:en

This document shows how to build Pyodide

Create A Virtual Machine through SlapOS to compile Pyodide

In SlapOS (How To create an account) click on Services, then Add

Adding a new service in SlapOS

From the list select KVM for Kernel-based Virtual Machine. Select the KVM Version. This document uses KVM version 1.0.67.

Set your own title, and set the parameters to 4GB RAM, 30GB Hard Disk Space and 1 External Disk. Computer Field is left empty. Click Proceed.

Virtual Machine Set Parameters

Let SlapOS set up the machine, after a while the links in 'Connection Parameters' at the bottom will populate. Wait until 'url' field is ready then click it.

Virtual Machine Connection Parameters

Install Debian on VM

After going to the url in Connection Parameters, you will be greeted with noVNC Screen. Press Connect. You should see the starting screen for installing debian. This version is going to install Debian 9.
Below is the list of settings used in this document. You may choose the ones which best fit you.

  • Install Debian
  • English Language
  • France Location
  • United States Local
  • French Keyboard
  • Hostname: debian
  • Domain Name: debian1
  • Set Root password
  • Set Username and password
  • All files in one partition
  • Yes; format disk
  • France package manager
  • france.ftp
  • Blank proxy information
  • Install os on hard disk, in dev/vda
  • Reboot
  • GNU/Linux

Log in

Debian 9 Desktop

Install Sudo and add your user to it

Open the Terminal and type the following commands:

su
apt-get install sudo
sudo adduser <username> sudo

Restart computer, log in again.

Install Sudo through Terminal

(Optional) Set Up Machine for SSH

Check if the machine has ssh_host keys needed to be ssh'ed into. In the terminal run

ls /etc/ssh

If the folder does not have _key and .pub files, you need to install openssh to be able to ssh into the machine. In the terminal run

sudo apt-get install openssh-server

Check /etc/hosts again to find an RSA key. Now you can ssh into the machine.

 

Check contents of /etc/ssh folder

For ssh you need the username, hostname and port. Username is the username of the account created in the virtual machine (in this case 'rs'). Host address can be found in
Slapos > Services > Your KVM Machine Service > Connection Parameters Table > nat-rule-port-22:

Virtual Machine Connection Parameters

In this case the hostname is '2001:67c:1254:e:c4::eb88' with port 10022. In terminal on your machine type

ssh [username]@[hostname] -p 10022

Then, enter the password for the username account.

 

Use SSH to connect with Virtual Machine

Download Prerequisites for Pyodide

Pyodide has prerequisites need to be able to build Pyodide locally. List of Prerequisites can be found in the Github Pyodide Repo

Create a new folder to contain all the files we will need to download.
In the terminal:

mkdir Pyodide
cd Pyodide

Location of Newly Created Pyodide Directory

Install emsdk Prerequisites

Pyodide will compile its own version of emsdk. emsdk Prerequisites for Linux are in its documentation page. All of them will be installed below.

First download emsdk itself.

sudo apt-get install git
git clone https://github.com/juj/emsdk.git

Install python3.7.0 on debian 9

Pyodide needs python 3.7.0 or newer. Instructions taken from StackExchange Post

Install these packages beforehand:

sudo apt-get install -y make build-essential libssl-dev zlib1g-dev 
sudo apt-get install -y libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm
sudo apt-get install -y libncurses5-dev  libncursesw5-dev xz-utils tk-dev

Then download Python source code and compile it.

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
tar xvf Python-3.7.0.tgz
cd Python-3.7.0
./configure --enable-optimizations
make -j8
sudo make altinstall
python3.7

Update path of python3 and python to point to the newly installed python.

sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.7 50
sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3.7 50
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 40
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 30

Install newest Nodejs and npm

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -

-

If you get ImportError: No module named 'lsb_release.py' while trying to install nodejs then update the location of lsb_release.py and run curlagain:

sudo ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.6/site-packages/lsb_release.py

-

After curl completes, install nodejs:

sudo apt-get install -y nodejs

Install PyYAML

Install the libYAML and it's headers

sudo apt-get install libyaml-dev

Download the pyyaml sources:

 

wget http://pyyaml.org/download/pyyaml/PyYAML-3.13.tar.gz

Install from sources:

tar xzf PyYAML-3.13.tar.gz
cd PyYAML-3.13
sudo python3 setup.py install
sudo python3 setup.py test 
cd ..

Install Cmake

sudo apt-get install -y cmake

Install ccache

sudo apt-get install -y ccache

Install Uglifyjs:

sudo npm install -g uglify-js

Install Less

sudo npm install -g less

Compile Pyodide

Clone the files from Pyodide github repo, go into the newly created directory with downloaded files and run make.

git clone https://github.com/iodide-project/pyodide.git
cd pyodide
make

Building updated Pyodide

Tip from @rth, building Pyodide the first time takes a long time, as LLVM has to build. Next time, you can shorten the build time by running:

make -C cpython clean
make

Instead of just make. It deletes cpython and builds Pyodide again, without having to rebuild LLVM and emsdk. Shortens build time to under 2 hours from 8 hours.