Objectives
In this Exercise you will learn how to:
- setup starter package with IOT fucntions
Prerequisites
Before you begin:
This Exercise requires that you have:
- Install Python 3.11.x in your environment.
- Install Git.
- Install pip3 package manager for Python.
- Install an editor such as Pycharm Community Edition
Setup Starter Package
- Clone the HelloWorld starter package .
- Open a terminal window.
- Make a new project folder for the starter package. For example, mkdir custom_function.
- Change to the project directory. For example, cd custom_function.
- Clone the starter package. Enter:
git clone --branch starter_package https://github.com/ibm-watson-iot/functions.git
- Verify that you cloned the starter package to the custom_function directory.
- Change to the functions directory in the starter package. Enter: cd functions
- Open the setup.py file. The setup.py file defines the package name and the list of packages that are required for the project.
- Set the name parameter to custom{your_initials}. Replace the {your_initials} variable with your initials or with another unique value.
- In the ibm-watson-iot/functions repository, verify that the iotfunction package is the
correct version. For example, for Maximo Monitor 9.1, the package must be from the 9.1.X GitHub branch. Do not replace the x in the version with another value. The following text is an example setup.py file. The name parameter is set to customId and the 9.1.X branch is used.
#!/usr/bin/env python from setuptools import setup, find_packages setup(name='customld', version='0.0.1', packages=find_packages(), install_requires=['iotfunctions@git+https://github.com/ibm-watson-iot/functions.git@9.1.x'])
Setup Pycharm
- Install the PyCharm community edition
- Open PyCharm and select Open to browse to your cloned directory.
- Next, create a Python virtual environment (venv) inside the custome_function folder by running the following command:
-
python3 -m venv venv-cust cd venv-cust/bin source activate
-
- Set up a virtual environment:
- Go to PyCharm > Preferences > Project > Python Interpreter
- Click the settings icon and select Add
- Set your venv folder location
- Set the base interpreter to your Python 3.11.x directory
- Run the following command to install the iotfunctions package into your Python environment. Ensure that you use the correct branch name for your version
pip3 install git+https://github.com/ibm-watson-iot/functions.git@9.1.x --upgrade
Note
Always use the IoT Functions version that matches your Maximo Monitor version to avoid pipeline issues.
Attention
If you're using a Mac Machine, you might encounter compatibility issues with the ibm_db package. Here's how to resolve them: Open the requirements.txt file Change ibm_db==3.2.3 to ibm_db==3.2.5 Save the file pip3 install -r requirements.txt
Congratulations you have successfully setup the starter package.