It is assumed that you have access to the SAP Business Technology Platform - either via your organization or via a free trial, as described in prerequisites.
If you are using SAP BTP Trial, then open it: https://hanatrial.ondemand.com/
If you are using the SAP BTP free trial, then open SAP Business Application Studio trial from the "Quick Tool Access" section.
Should you have issues opening SAP Business Application Studio (for example when you have had the account for a long time), then check the steps in this tutorial - Set Up SAP Business Application Studio for Development
Go to your instance of SAP Business Application Studio (further referred to as "BAS").
For this SAP CodeJam exercise create a new Dev Space called CodeJamHANAML
of a kind Basic with an additional extension Python Tools in BAS:
Screen element | Value |
---|---|
Dev Space name | CodeJamHANAML |
Kind | Basic |
Additional extension | Python Tools |
You should see the dev space STARTING.
Wait for the dev space to get into the RUNNING state and then open that dev space.
Once your dev space is open in the BAS, use one of the available options to clone this Git repository with exercises using the URL 👇🏼
https://github.com/SAP-samples/hana-ml-py-codejam.git
☝🏻 into your project
directory in the BAS Dev Space.
Click Open to open a project in the Explorer view.
The cloned repository contains a file codejam.code-workspace
and therefore you will be asked, if you want to open it. Click Open Workspace.
If you missed the previous dialog, then you can go to the BAS Explorer, click on the codejam.code-workspace
file, and then click on the Open Workspace.
You should see:
- CODEJAM as the workspace at the root of the hierarchy of the project, and
hana-ml-py-codejam
as the name of the top level folder.
SAP provides you with a mechanism to access third-party sites to view and download open-source, 3rd party or its own tools, libraries, or software components ("Extensions") to dev spaces in SAP Business Application Studio. Using this mechanism, you can view and install VS Code Extensions from the VSX Open Registry at your own risk.
Go to Extensions using the activity bar (the left-most bar in the IDE) and type @builtin Py
in the search bar.
You should see Python and Jupyter extensions installed already.
The built-in venv module in Python provides support for creating lightweight “virtual environments”. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.
Open a built-in terminal in BAS, eg. using the menu option.
Make sure you are in the /home/user/projects/hana-ml-py-codejam
directory, e.g., using the pwd
command.
Use venv
to create a virtual environment for your project in the new directory ~/projects/hana-ml-py-codejam/env
by using the following command:
python3 -m venv ~/projects/hana-ml-py-codejam/env --upgrade-deps
Check that the virtual environment was successfully created:
ls -l ~/projects/hana-ml-py-codejam/env
Activate the virtual environment using the following command:
source ~/projects/hana-ml-py-codejam/env/bin/activate
You should see you are in a virtual environment as indicated by the (env)
prefix in a shell's prompt.
Install:
- the
ipykernel
package to be able to run Python code in a Jupyter extension using the following command:
python -m pip install --require-virtualenv --no-cache-dir ipykernel
- the Python machine learning client for SAP HANA (
hana-ml
) and other required dependencies listed in https://help.sap.com/doc/cd94b08fe2e041c2ba778374572ddba9/2024_1_QRC/en-US/Installation.html#installation-guide using the following command:
python -m pip install --require-virtualenv --no-cache-dir -U 'hana-ml==2.22.*' ipywidgets 'jinja2>=3.0.0' pydotplus graphviz 'shapely>=1.7.1' 'matplotlib' plotly setuptools
- Install Jupyter's own utilities for programmatic work with notebook documents:
nbformat
to be able to run one notebook from another, andnbconvert
to be able to clean the output of notebooks, eg. before pushing to the Git repository, using the following command:
python -m pip install --require-virtualenv --no-cache-dir nbformat nbconvert
In your BAS hide the terminal.
Go to Explorer and open a exercises/010-check_setup.ipynb
notebook.
The notebook should open in a Jupyter extension.
Next, select a kernel env
(the virtual environment you set up earlier) from Python Environments.
The kernel should be set in a few seconds. You should get messages about Jupyter server processes started in the background ready to execute code from your notebook.