33 lines
1.6 KiB
Markdown
33 lines
1.6 KiB
Markdown
# Use Python with Occlum
|
|
|
|
This project demonstrates how Occlum enables _unmodified_ [Python](https://www.python.org) programs running in SGX enclaves, which is based on glibc.
|
|
|
|
## Sample Code: CSV Processing in Python
|
|
|
|
To make the sample code more realistic, we choose to write a Python program that processes CSV data files using [NumPy](https://numpy.org), [pandas](https://pandas.pydata.org), and [scikit-learn](https://scikit-learn.org). The sample code can be found [here](demo.py).
|
|
|
|
## How to Run
|
|
|
|
This tutorial is written under the assumption that you have Docker installed and use Occlum in a Docker container.
|
|
|
|
Occlum is compatible with glibc-supported Python, we employ miniconda as python installation tool. You can import any python dependencies using conda. Here, miniconda is automatically installed by install_python_with_conda.sh script, the required python and related dependencies for this project are also loaded by this script. Here, we take occlum/occlum:0.23.0-ubuntu18.04 as example.
|
|
|
|
Step 1 (on the host): Start an Occlum container
|
|
```
|
|
docker pull occlum/occlum:0.23.0-ubuntu18.04
|
|
docker run -it --name=pythonDemo --device /dev/sgx/enclave occlum/occlum:0.23.0-ubuntu18.04 bash
|
|
```
|
|
|
|
Step 2 (on the host): Download miniconda and install python to prefix position.
|
|
```
|
|
cd /root/occlum/demos/python/python_glibc
|
|
bash ./install_python_with_conda.sh
|
|
```
|
|
|
|
Step 3 (on the host): Run the sample code on Occlum
|
|
```
|
|
cd /root/occlum/demos/python/python_glibc
|
|
bash ./run_python_on_occlum.sh
|
|
```
|
|
It will process CSV data files and generate a file (`smvlight.dat`) in `./occlum_instance`.
|