Teradata Package for Python Function Reference on VantageCloud Lake - create_env - Teradata Package for Python - Look here for syntax, methods and examples for the functions included in the Teradata Package for Python.
Teradata® Package for Python Function Reference on VantageCloud Lake
- Deployment
- VantageCloud
- Edition
- Lake
- Product
- Teradata Package for Python
- Release Number
- 20.00.00.03
- Published
- December 2024
- ft:locale
- en-US
- ft:lastEdition
- 2024-12-19
- dita:id
- TeradataPython_FxRef_Lake_2000
- Product Category
- Teradata Vantage
- teradataml.scriptmgmt.lls_utils.create_env = create_env(env_name=None, base_env=None, desc=None, template=None, conda_env=False)
- DESCRIPTION:
Creates isolated remote user environment(s) in the Open Analytics
Framework that include 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, additionally, files/libs are
installed if specified in template file. Out of provided specifications in
template file, if any of the environment creation fails, failure message is
printed on console and next environment creation is taken up.
PARAMETERS:
env_name:
Required when "template" is not used, optional otherwise.
Specifies the name of the environment to be created.
Note:
Either "env_name" or "template" argument must be specified.
Types: str
base_env:
Optional Argument.
Specifies the name of the base Python or R environment
to be used to create remote user environment when "env_name"
is provided. This argument is ignored when "template" is provided.
Notes:
* When "base_env" is not provided, highest Python
base environment listed by list_base_envs() is used.
* When creating a conda environment, user can pass any Python version
supported by Anaconda to "base_env", irrespective of base environments
listed with list_base_envs().
Types: str
desc:
Optional Argument.
Specifies description for the remote environment when "env_name"
is provided. This argument is ignored when "template" is provided.
Default value: "This env '<env_name>' is created with base env
'<base_env>'."
Types: str
template:
Required when "env_name" is not used, optional otherwise.
Specifies the path to template json file containing details
of the user environment(s) to be created. Using the template
file one can create one or more user environments with same or
different requirements. This template file can contain following
information about the environments to be created:
* Name of the environment. (Required)
* Base Python version to be used. (Optional)
* Description for the environment. (Optional)
* Files or libraries to be installed in the environment. (Optional).
Here is a sample example of the template file:
{
"env_specs" : [
{
"env_name" : "<name of the user environment_MUST_BE_SPECIFIED>",
"base_env" : "<OPTIONAL_base_env>",
"desc": "<OPTIONAL_env_description>",
"libs": ["<OPTIONAL>", "<List_of_libs_to_be_installed>"] OR "<location_of_requirements.txt>"
"files": ["<OPTIONAL>", "<full_path_the_file>", "<full_path_to_dir>"]
},
{
"env_name" : "....",
"base_env" : "...",
"desc": "..",
"libs": ..
"files": ...
},
{
...
},
{
...
}
]
}
Notes:
* Either "template" or "env_name" argument must be specified.
* Template file can contain details about single or multiple
environments to be created. At least one is required.
* Content of template file should adhere to the syntax mentioned
above. Check example for more details.
Types: str
conda_env:
Optional Argument.
Specifies whether the environment to be created is a conda environment or not.
When set to True, conda environment is created.
Otherwise, non conda environment is created.
Note:
* Currently, only Python conda environment is supported.
Default value: False
Types: bool
RETURNS:
An object of class UserEnv representing the user environment.
When template file provided with "template" has specifications for multiple
environments, an object of class UserEnv representing last created environment
is returned.
RAISES:
TeradataMlException.
EXAMPLES:
# List all available user environments.
>>> list_base_envs()
base_name language version
0 python_3.7.13 Python 3.7.13
1 python_3.8.13 Python 3.8.13
2 python_3.9.13 Python 3.9.13
3 python_3.10.5 Python 3.10.5
4 r_4.1 R 4.1.3
5 r_4.0 R 4.0.5
6 r_4.2 R 4.2.2
# Example 1: Create a Python 3.7.13 environment with given name and description in the 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 the 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/libraries
# in those 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 the 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.