Open Analytics Anaconda Python User Environment | Open Analytics Framework | VantageCloud Lake - Open Analytics Python conda User Environment - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
Language
English (United States)
Last Update
2024-04-03
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

As an Open Analytics Framework user, you can create Python conda environments, install Python libraries for different analytics use cases such as predicting the next value in a Time Series Sequence, sentiment analysis, and so on.

The following steps show how to use teradataml function calls to create a Python conda user environment and install libraries, to make use of Anaconda to build your Open Analytics solution.

Complete code samples of use cases can be found in the Use Cases using Python Conda Environments section.

Create Python conda User Environment

To create a Python conda user environment, set the conda_env argument to 'True' in the create_env funcation call.

You must follow instructions in Enabling Anaconda for Open Analytics to enable Anaconda for the VantageCloud Lake environment before you can create an Open Analytics Framework conda user environment.
  • Assume you want to create a new Python conda user environment equipped with Python 3.10.
    demo_env = create_env(env_name='py_numpy_env',
                          base_env='python_3.10',
                          desc='py test env', 
                          conda_env=True)
    Conda environment creation initiated
    User environment 'py_numpy_env' created.
    You can specify a particular version of Python when creating a new Python conda environment or when installing packages.

    For example, as shown here, if you want to create a conda environment using Python 3.10, then specify 'python_3.10' in the base_env field.

  • Verify the new environment has been created.
    list_user_envs()
      env_name      env_description     base_env_name   language   conda
    0 py_numpy_env  py test env         python_3.10     Python     True

Once the environment is created, you can use the user environment handler to manage the environment and install the libraries needed for analysis.

The following sections list some of the teradataml functions that are used to manage user environment and libraries for analytics. See APIs to Manage User Environments and APIs to Manage Files and Libraries inside a User Environment for detailed descriptions and more examples for these functions.

View existing libraries in a User Environment

demo_env.libs
             name      version 
0   _libgcc_mutex          0.1 
1   _openmp_mutex          5.1 
2           bzip2        1.0.8 
3 ca-certificates   2023.12.12 
4 d_impl_linux-64.        2.38 
5          libffi        3.4.4 
6       libgcc-ng       11.2.0 
7         libgomp       11.2.0 
8    libstdcxx-ng       11.2.0 
9         libuuid       1.41.5 
10        ncurses          6.4 
11        openssl       3.0.12 
12            pip       23.3.1 
13         python      3.10.13 
14       readline           8. 
15     setuptools       68.2.2 
16         sqlite       3.41.2 
17             tk       8.6.12 
18         tzdata        2023d 
19          wheel       0.41.2 
20             xz        5.4.5 
21           zlib       1.2.13

Install libraries in a User Environment

There are two ways to install libraries in a user environment.

The libraries for Anaconda are downloaded from one of the two secure Anaconda channels, either https://repo.anaconda.com/pkgs/main/linux-64/ or https://repo.anaconda.com/pkgs/main/noarch/.
  • Install libraries by specifying the libraries names directly in the install_lib() function.

    The function installs any dependencies in the user environment as well.

    For example:
    claim_id = demo_env.install_lib(['numpy'], asynchronous=True)
  • Install libraries by specifying the libraries names in a requirement file.

    Requirement file in Python is commonly used to specify the external dependencies that your project or script needs to run.

    The requirement file must be specified in the install_lib() function by means of the file location in your filepath.

    For example:
    claim_id = demo_env.install_lib(libs_file_path=os.path.join(path_to_reqsfiles, 'reqs_numpy.txt'), asynchronous=False)
    Sample text file content for the requirement file reqs_numpy.txt could be:
    numpy

The default value of the asynchronous parameter is False, which means you need to wait until installation is complete to proceed with the next statement. However, by specifying asynchronous=True, teradataml enables you to continue executing statements while installation takes place asynchronously in the background. Avoid using the libraries you requested before installation is complete.

During asynchronous installation, you can check the status by using the status API. For example:
demo_env.status(claim_id)
You can verify that the desired Python libraries have been installed correctly by using the libs API. For example:
demo_env.libs()

Upgrade libraries in a User Environment

Upgrade libraries in a user environment by specifying the library names directly in the update_lib() function. Conda attempts to install the newest versions of the requested packages.

For Anaconda, update_lib() accepts only package names, and updates them to the latest versions that are compatible with all other packages in the environment.

For example:
demo_env.update_lib([‘numpy’], asynchronous=True)
Do not provide a specific package version when upgrading libraries. If you want to specify a version, you need to use conda install instead.

Uninstall libraries in a User Environment

Uninstall libraries in a user environment by specifying the library names directly in the update_lib() function.

For example:
demo_env.uninstall_lib([‘numpy’], asynchronous=True)
Request to uninstall libraries initiated successfully in the remote user environment pytest_sim4. Check the status using status() with the claim id '77509db2-c31e-463f-9d22-6865f46f65ee'.