Transformations > Python transformation > Install and configure Python
  

Install and configure Python

If needed, install and configure Python to run code to run on a Secure Agent machine.
Informatica packages a default Python version in the Secure Agent installation. If this version meets your needs, you can use it without further configuration. If you need third-party libraries or a specific version of Python, install and configure a custom Python installation.
Note:
You can't create a custom Python installation when you use a serverless runtime environment.
To install and configure Python, complete the following tasks:
  1. 1Install the prerequisite packages on the Secure Agent machine.
  2. 2Download the version of Python that you want to install on the Secure Agent machine and extract the files.
  3. 3Prepare the installation directory.
  4. 4Compile and build the Python installation.
  5. 5Set environment variables to allow the Secure Agent machine access to the installation.
  6. 6Verify the installation contains the correct folders.
  7. 7Install the str2bool library and any additional third-party libraries.
  8. 8Copy the installation to the Secure Agent machine.
  9. 9If your installation uses third-party libraries, verify their installation.
  10. 10Configure the mapping task to use the custom Python installation.

Step 1. Install prerequisite packages

Before you install Python, make sure that the Secure Agent machine has the required packages.
Install the following packages on the agent machine:
Use the appropriate installation commands for your package manager. For example, to use the yum package manager, run the following commands:
sudo yum install libffi-devel
sudo yum install openssl-devel
sudo yum install zlib-devel

Step 2. Download the Python distribution

Find the version of Python that you want to install on the Secure Agent machine and extract the files.
  1. 1Navigate to the home directory.
  2. 2Download the Python distribution onto the Secure Agent machine.
  3. For example, you can run the following command to get an installation of Python 3.6.5 from the internet:
    wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
    This command downloads the Python distribution in the home directory.
  4. 3To extract the contents, run the following command :
  5. tar -xvf <file name>
    For example, to extract the contents of the file Python-3.6.5.tgz, run the following command:
    tar -xvf Python-3.6.5.tgz
    The extracted files appear in the directory ~/Python-3.6.5.

Step 3. Prepare a directory to install Python

Specify a location to contain the Python installation. To prepare an installation directory, run commands to create a directory and set it as the working directory.
  1. 1To create a directory under the home directory, run the following command:
  2. mkdir <directory name>
  3. 2To create an environment variable called $workingdir and set the value to the present working directory, run the following command:
  4. export workingdir=`pwd`
  5. 3To verify the $workingdir environment variable, run the following command:
  6. echo $workingdir

Step 4. Install Python

Run commands to compile and build the Python installation.
  1. 1Use cd to navigate to the directory where you extracted the Python distribution. For example:
  2. cd Python-3.6.5
  3. 2Compile Python under the working directory. For example, run the following command:
  4. ./configure --enable-shared --prefix=$workingdir/Python3
  5. 3To build the Python installation, run the following commands:
  6. make
    make install

Step 5. Set environment variables

Configure the Secure Agent machine to access the Python installation.
  1. 1Set the PYTHONHOME environment variable to the directory where you installed Python. For example, run the following command:
  2. export PYTHONHOME=$workingdir/Python3
  3. 2To set the LD_LIBRARY_PATH environment variable, run the following command:
  4. export LD_LIBRARY_PATH=$PYTHONHOME/lib
  5. 3To set the PATH environment variable, run the following command:
  6. export PATH=$PYTHONHOME/bin:$PATH
  7. 4Restart the Secure Agent.

Step 6. Verify the Python installation

Confirm the location of the installation folders.
  1. 1To change the directory to $PYTHONHOME, run the following command:
  2. cd $PYTHONHOME
  3. 2To verify that $PYTHONHOME contains the required folders, run the command ls.
  4. The directory should contain the following folders:

Step 7. Install third-party libraries

Install the str2bool library and any additional libraries that you need.
Custom Python installations require the str2bool library. Use the following pip command to install the str2bool library in $PYTHONHOME:
bin/pip3 install str2bool
If your Python installation uses other third-party libraries, use additional pip commands to install them.
For example, you can run the following commands to install numpy and scikit-learn:
bin/pip3 install numpy
bin/pip3 install scikit-learn

Step 8. Copy Python to the Secure Agent machine

Copy the Python installation to the Secure Agent machine.
To complete the Python installation, run the following commands:
  1. 1Create the following directory on the Secure Agent machine if it doesn't exist: <Secure Agent installation directory>/ext/python/
  2. 2To copy the Python installation to the Secure Agent machine, run the following command:
  3. cp -r $PYTHONHOME/* <Secure Agent installation directory>/ext/python/
  4. 3To check the contents of the Informatica domain, run the following command:
  5. ll <Secure Agent installation directory>/ext/python/
  6. 4Verify that the contents include the following folders:

Step 9. Optionally, verify third-party library installations

If your Python installation uses third-party libraries, make sure they are installed on the Secure Agent machine.
  1. 1To change directories to the Secure Agent machine, run the following command:
  2. cd <Secure Agent installation directory>/ext/python/
  3. 2To invoke the Python interpreter, run the following command:
  4. bin/python3
  5. 3Use import commands to verify the installation of each third-party library. For example, run the following commands:
  6. import numpy
    import sklearn
  7. 4Verify that the import statement is successful for each Python third-party library that you installed. Then, you can press Ctrl+D to exit the Python interpreter.

Step 10. Configure the mapping task

After you create a mapping with a Python transformation, configure the mapping task to use the custom Python installation.
In the mapping task, configure an advanced session property to specify the locations of the custom Python installation directory and Python executable.
  1. 1In the mapping task advanced session properties, click Add.
  2. 2For the session property name, select Custom Properties.
  3. 3For the session property value, enter the following custom properties:
  4. Property
    Description
    infaspark.pythontx.executorEnv.PYTHONHOME
    The location of the Python installation directory on the Secure Agent machine. The default value is $INFA_HOME/python3.
    infaspark.pythontx.exec
    The location of the Python executable on the Secure Agent machine. The default value is $INFA_HOME/python3/bin/python3.
    Use &: to spearate the key-value pairs. For example, you might enter the following value: infaspark.pythontx.executorEnv.PYTHONHOME=$INFA_HOME/python&:infaspark.pythontx.exec=$INFA_HOME/python/bin/python3