Use the create_env function to create isolated remote user environment or environments in the Open Analytics Framework that includes a specific Python or R language interpreter version. Available base Python or R environments can be found using list_base_envs function.
When template argument is provided, files and libs are installed if specified in the template file.
You can create multiple environments based on the specifications in a single template file. If an environment creation fails, a failure message appears on console and the next environment creation starts.
Optional Arguments
- env_name
- Specifies the name of the environment to be created.This argument is required when template is not used. Otherwise, it is optional.
- template
- Specifies the path to template json file containing details of the user environment or environments to be created.This argument is required when env_name is not used. Otherwise, it is optional.
- base_env
- Specifies the name of the Python or R base environment to be used to create remote user environment, when env_name is provided.
- desc
- Specifies description about the remote environment when env_name is provided.
- conda_env
- Specifies whether the environment to be created is a conda environment.
This function returns an object of class UserEnv representing the remote user environment.
When template file provided with template argument has specifications for multiple environments, an object of class UserEnv representing the last created environmentis returned.
Example 1: Create a Python 3.7.13 environment with given name and description in Vantage
>>> fraud_detection_env = create_env('Fraud_detection', 'python_3.7.13', 'Fraud detection through time matching')
User environment 'Fraud_detection' created.
Example 2: Create a R 4.1.3 environment with given name and description in Vantage
>>> fraud_detection_env = create_env('Carbon_Credits', 'r_4.1', 'Prediction of carbon credits consumption')
User environment 'Carbon_Credits' created.
Example 3: Create multiple environments, and install files and libraries
This example creats multiple environments and install files and libraries in these environments by providing specifications in template file.
- Create a template json file.
>>> import teradataml, os, json
>>> tdml_data_path = os.path.join(os.path.dirname(teradataml.__file__), "data") python_base_env = "python_3.9.13" r_base_env = "r_4.1" env_specs = [ { "env_name": "env_1", "base_env": python_base_env, "desc": "Desc for test env 1" }, { "env_name": "env_2", "base_env": r_base_env, "libs": ["glm2", "stringi"] "files": [os.path.join(tdml_data_path, "load_example_data.py"), os.path.join(tdml_data_path, "scripts")] } ] json_data = {"env_specs": env_specs} with open("template.json", "w") as json_file: json.dump(json_data, json_file)
- Create environments.
>>> create_env(template="template.json")
Creating environment 'env_1'... User environment 'env_1' created. An empty environment 'env_1' is created. Created environment 'env_1' with specified requirements. Environment Name: env_1 Base Environment: python_3.9.13 Description: Desc for test env 1 Creating environment 'env_2'... User environment 'env_2' created. An empty environment 'env_2' is created. Installing files in environment 'env_2'... File 'load_example_data.py' installed successfully in the remote user environment 'env_2'. File 'mapper.py' installed successfully in the remote user environment 'env_2'. File 'mapper.R' installed successfully in the remote user environment 'env_2'. File 'mapper_replace.py' installed successfully in the remote user environment 'env_2'. File installation in environment 'env_2' - Completed. Created environment 'env_2' with specified requirements. Environment Name: env_2 Base Environment: r_4.1 Description: This env 'env_2' is created with base env 'r_4.1'. ############ Files installed in User Environment ############ File Size Timestamp 0 mapper.py 547 2023-11-07T10:14:06Z 1 mapper.R 613 2023-11-07T10:14:09Z 2 load_example_data.py 14158 2023-11-07T10:14:03Z 3 mapper_replace.py 552 2023-11-07T10:14:12Z ############ Libraries installed in User Environment ############ name version 0 KernSmooth 2.23-20 1 MASS 7.3-55 2 Matrix 1.4-0 3 base 4.1.3 4 boot 1.3-28 5 class 7.3-20 6 cluster 2.1.2 7 codetools 0.2-18 8 compiler 4.1.3 9 datasets 4.1.3 10 foreign 0.8-82 11 grDevices 4.1.3 12 graphics 4.1.3 13 grid 4.1.3 14 lattice 0.20-45 15 methods 4.1.3 16 mgcv 1.8-39 17 nlme 3.1-155 18 nnet 7.3-17 19 parallel 4.1.3 20 remotes 2.4.2 21 rpart 4.1.16 22 spatial 7.3-15 23 splines 4.1.3 24 stats 4.1.3 25 stats4 4.1.3 26 survival 3.2-13 27 tcltk 4.1.3 28 tools 4.1.3 29 utils 4.1.3
Example 4: Create a conda Python 3.8 environment with given name and description in Vantage
>>> fraud_detection_env = create_env('Fraud_detection_conda', 'python_3.8', 'Fraud detection through time matching', conda_env=True)
Conda environment creation initiated User environment 'Fraud_detection_conda' created.