Last summer, Muhammad Altaf posted Getting Started with Python on SAP HANA XSA showing the steps how to install/create the Python runtime for SAP HANA XS advanced model. Judging by the number of views, this topic is of interest for the HANA development community.
Hence, “to enhance your learning experience”, we have created a tutorial video where you can see this in action using two sample code scripts.
In the video tutorial, we show how you –using SAP HANA, express edition running in Google Cloud, as example — how to prepare the OS environment, how to build Python and create the runtime. A simple test script generates a sample app to validate all is well in the best possible worlds.
For the sample code, see the GitHub repository:
The code sample below shows how to clone the repository to your HANA development system.
sudo -i su - hxeadm cd $HOME git clone https://github.com/saphanaacademy/python cd python chmod u+x *.sh ./create-python-runtime.sh ./test-python-runtime.sh
Operating System Preparation
Every carpenter knows; before you can build, you need tools. An SAP HANA system, as an appliance, in express edition format, or when hardened, does not include any build tools. Not needed, overhead, potentially insecure. To build Python runtimes, you will first need to add the required packages to your system.
The SAP HANA Developer Guide documents the following packages as requirements:
zypper install tk-devel tcl-devel libffi-devel \ openssl-devel readline-devel sqlite3-devel \ ncurses-devel xz-devel zlib-devel
Should you still have issues with building, on a development system, consider to install the Basis-Devel pattern.
zypper search -t pattern zypper in -t pattern Basis-Devel
If you prefer, you can use YaST2.
You can download the Python source code from https://www.python.org/downloads/source/
The create runtime script downloads the version, configures, makes and altinstalls. The version is taken as input. We run altinstall because we do not want to update either the Linux Python release or the HANA Python version,
Note that the path here is a hardcoded HXE. If you are not using the express edition, change the path to the SID.
cd ~ ; mkdir -p builds source Downloads wget -P ~/Downloads \ -N https://www.python.org/ftp/python/$1/Python-$1$2.tgz tar xzvf ~/Downloads/Python-$1$2.tgz -C ~/source cd ~/source/Python-$1$2 ./configure \ --prefix=/usr/sap/HXE/home/builds/Python-$1$2 \ --exec-prefix=/usr/sap/HXE/home/builds/Python-$1$2 \ --enable-optimizations make altinstall clean xs create-runtime -p ~/builds/Python-$1$2 xs runtimes
Testing, Testing, 1,2,3
The test script generates the required files for a simple Hello World python script:
# create server.py cat > server.py << EOF import os from flask import Flask app = Flask(__name__) port = int(os.environ.get('PORT', 3000)) @app.route('/') def hello(): return "Hello World from Python $1" if __name__ == '__main__': app.run(port=port) EOF
To upload the app, we switch to the development space and push (upload) the app to the runtime. For housekeeping, we delete the app first (if present).
Note that “development” is one of the spaces available out-of-the-box with SAP HANA, express edition. If you are working on a regular platform edition, you might need to change the name otherwise xs push will default to the ‘SAP’ space (not recommended).
xs target -s development xs delete -f pyapp xs push
The tutorials has been posted to the following playlists:
For the documentation, see
- Building from Sources and Deploying the Python Run Time to XS Advanced – SAP HANA Developer Guide for SAP HANA XS Advanced Model
Thank you for watching
The SAP HANA Academy provides free online video tutorials for the developers, consultants, partners and customers of SAP HANA.
Topics range from practical how-to instructions on administration, data loading and modeling, and integration with other SAP solutions, to more conceptual projects to help build out new solutions using mobile applications or predictive analysis.
For the full library, see SAP HANA Academy Library – by the SAP HANA Academy.
For the full list of blogs, see Blog Posts – by the SAP HANA Academy.