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/hello.py example.

Installation

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:
1
$ pip3 install ~/.hadean/sdk/etc/packages/python/hadean-0.0.1.tar.gz
Copied!
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:
1
$ python3 --version
2
Python 3.9.2
3
4
# let's export a variable to make things easier
5
$ export PY_VERSION="3.9"
Copied!
Now we can go ahead and run our application:
1
$ hadean run $(which python3) \
2
--mappings \
3
/usr/lib/python$PY_VERSION/ \
4
/usr/lib/python$PY_VERSION/hadean=$HOME/.local/lib/python$PY_VERSION/site-packages/hadean \
5
./hello.py=$HOME/hadean/examples/python/hello.py \
6
-- \
7
./hello.py
8
9
[2022-01-18T16:33:18Z INFO ] Starting application...
10
[2022-01-18T16:33:32Z INFO ] 127.0.0.1.18003.0: Hello from parent!
11
[2022-01-18T16:33:32Z INFO ] 127.0.0.1.18003.0: Child says Hello!
12
[2022-01-18T16:33:33Z INFO ] Application exited (0)
Copied!
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 hello.py 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 hello.py 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:
1
[2022-01-18T16:36:23Z INFO ] Starting application...
2
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Could not find platform independent libraries <prefix>
3
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Could not find platform dependent libraries <exec_prefix>
4
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
5
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Python path configuration:
6
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: PYTHONHOME = (not set)
7
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: PYTHONPATH = (not set)
8
...
Copied!