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.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
.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 \
./hello.py=$HOME/hadean/examples/python/hello.py \
-- \
./hello.py
[2022-01-18T16:33:18Z INFO ] Starting application...
[2022-01-18T16:33:32Z INFO ] 127.0.0.1.18003.0: Hello from parent!
[2022-01-18T16:33:32Z INFO ] 127.0.0.1.18003.0: 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
hello.py
example we need a few things:python3
which is copied byhadean 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:[2022-01-18T16:36:23Z INFO ] Starting application...
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Could not find platform independent libraries <prefix>
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Could not find platform dependent libraries <exec_prefix>
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: Python path configuration:
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: PYTHONHOME = (not set)
[2022-01-18T16:36:24Z ERROR] 127.0.0.1.18003.0: PYTHONPATH = (not set)
...