BYOR: Setup Python Runtime for XSA – by the SAP HA...
Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
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.
Tutorial Video
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.
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:
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:
runtime.txt
requirements.txt
manifest.yaml
server.py
# 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
YouTube Playlist(s)
The tutorials has been posted to the following playlists:
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.