Running a Python3 application

The Hadean Platform SDK also comes with Python bindings. In this tutorial we will look at how we can install them and use them to run the ~/hadean/examples/python/ example.


In order to install the bindings, you will need the following dependencies:
  • swig
  • python3 (version >= 3.5)
  • pip3
  • pkg-config
Once we have these, we can go ahead and install the bindings:
$ pip3 install ~/.hadean/sdk/etc/packages/python/hadean-0.0.1.tar.gz
The above will install the bindings into ./local/lib/python$PYTHON_VERSION.

Running an example

First, let's find out the version of Python we are running:
$ python3 --version
Python 3.9.2
# let's export a variable to make things easier
$ export PY_VERSION="3.9"
Now we can go ahead and run our application:
$ hadean run $(which python3) \
--mappings \
/usr/lib/python$PY_VERSION/ \
/usr/lib/python$PY_VERSION/hadean=$HOME/.local/lib/python$PY_VERSION/site-packages/hadean \
./$HOME/hadean/examples/python/ \
-- \
[2022-01-18T16:33:18Z INFO ] Starting application...
[2022-01-18T16:33:32Z INFO ] Hello from parent!
[2022-01-18T16:33:32Z INFO ] Child says Hello!
[2022-01-18T16:33:33Z INFO ] Application exited (0)
So what happened there, and what's up with that --mappings argument?
Our application runs in a sandboxed environment, but in order to run our example we need a few things:
  • python3 which is copied by hadean run for us
  • the standard Python3 packages, which are found in /usr/lib/python
  • the hadean module
  • the file which we want Python to execute
The --mappings argument helps us move a set of files and directories into the environment in which python3 will run. Without "mapping" these files, python3 would probably output something like:
[2022-01-18T16:36:23Z INFO ] Starting application...
[2022-01-18T16:36:24Z ERROR] Could not find platform independent libraries <prefix>
[2022-01-18T16:36:24Z ERROR] Could not find platform dependent libraries <exec_prefix>
[2022-01-18T16:36:24Z ERROR] Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
[2022-01-18T16:36:24Z ERROR] Python path configuration:
[2022-01-18T16:36:24Z ERROR] PYTHONHOME = (not set)
[2022-01-18T16:36:24Z ERROR] PYTHONPATH = (not set)