uninstall_lib | Manage files and libs in User Environment | OpenAF - uninstall_lib - Teradata Vantage

Teradata® VantageCloud Lake

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

Use the uninstall_lib function to uninstall libraries from corresponding Python or R user environment.

Optional Arguments

Either libs or libs_file_path argument must be specified.
libs
Specifies the library names.
libs_file_path
Specifies the absolute or relative path of the file (including file extension) which supplies a list of libraries to be uninstalled from remote user environment.
The path specified must include the filename with extension.
The file must contain library names of the libraries, and version number is optional.
This file format should adhere to the specifications of the requirements file used by underlying language's package manager for uninstalling libraries.
The file must have a ".txt" extension for Python environment. Sample text file contents for Python:
    numpy
    joblib==0.13.2
The file must have a ".txt" or ".json" extension for R environment. Sample json file contents for R:
{
    "packages": ["anytime","glm2"]
}

**kwargs: Specifies the keyword arguments.

asynchronous
Specifies whether to uninstall the library in remote user environment synchronously or asynchronously.
Default value is False.
Do not use remove_env() on the same environment till the asynchronous call is complete.
timeout
Specifies the time to wait in seconds for uninstalling the libraries.
If the library is not uninstalled within timeout seconds, the function returns a 'claim_id' and you can check the status using the 'claim_id'.
If timeout is not specified, then there is no limit on the wait time.
This argument is ignored when argument asynchronous is True.
The return of this function depends on whether libraries are uninstalled asynchronously:
  • If libraries are uninstalled synchronously, it returns a pandas DataFrame.
  • If libraries are uninstalled asynchronously, it returns a string type 'claim_id' to track status.

Examples for Python environment

Example Prerequisite

Create remote Python user environment for the following examples 1-4.

>>> testenv = create_env('testenv', 'python_3.7.9', 'Test environment')
User environment testenv created.

Example 1: Install and uninstall a single Python library asynchronously

  • Install Python library 'numpy'.
    >>> testenv.install_lib('numpy')
                                   Claim Id File/Libs  Method Name     Stage             Timestamp Additional Details
    0  407e644d-3630-4085-8a0b-169406f52340     numpy  install_lib   Started  2022-07-13T11:32:32Z               None
    1  407e644d-3630-4085-8a0b-169406f52340     numpy  install_lib  Finished  2022-07-13T11:32:33Z               None
  • Verify if libraries are installed.
    >>> testenv.libs
          library  version
    0       numpy  1.21.6
    1         pip  20.1.1
    2  setuptools  47.1.0
  • Uninstall single Python library asynchronously.
    >>> testenv.uninstall_lib('numpy', asynchronous=True)
    Request to uninstall libraries initiated successfully in the remote user environment testenv.
    Check the status using status() with the claim id '16036846-b9d7-4c5b-be92-d7cf14aa2016'.
  • Check the status.
    >>> testenv.status('16036846-b9d7-4c5b-be92-d7cf14aa2016')
                                   Claim Id File/Libs    Method Name     Stage             Timestamp Additional Details
    0  16036846-b9d7-4c5b-be92-d7cf14aa2016     numpy  uninstall_lib   Started  2022-07-13T11:33:42Z               None
    1  16036846-b9d7-4c5b-be92-d7cf14aa2016     numpy  uninstall_lib  Finished  2022-07-13T11:33:42Z               None
  • Verify library is uninstalled.
    >>> testenv.libs
        library     version
    0   pip         20.1.1
    1   setuptools  47.1.0

Example 2: Install list of Python libraries asynchronously and uninstall these libraries synchronously

  • Install multiple libraries asynchronously.
    >>> testenv.install_lib(["pandas", "scikit-learn"], asynchronous=True)
    Request to install libraries initiated successfully in the remote user environment testenv.
    Check the status using status() with the claim id 'a91af321-cf57-43cc-b864-a67fa374cb42'.
  • Check the status.
    >>> testenv.status('a91af321-cf57-43cc-b864-a67fa374cb42')
                                   Claim Id             File/Libs  Method Name     Stage             Timestamp Additional Details
    0  a91af321-cf57-43cc-b864-a67fa374cb42  pandas, scikit-learn  install_lib   Started  2022-07-13T11:34:38Z               None
    1  a91af321-cf57-43cc-b864-a67fa374cb42  pandas, scikit-learn  install_lib  Finished  2022-07-13T11:36:40Z               None
  • Verify libraries are installed along with dependent libraries.
    >>> testenv.libs
                library version
    0            joblib   1.1.0
    1             numpy  1.21.6
    2            pandas   1.3.5
    3               pip  20.1.1
    4   python-dateutil   2.8.2
    5              pytz  2022.1
    6      scikit-learn   1.0.2
    7             scipy   1.7.3
    8        setuptools  47.1.0
    9               six  1.16.0
    10    threadpoolctl   3.1.0
  • Uninstall the libraries by passing a list of library names.
    >>> testenv.uninstall_lib(["pandas", "scikit-learn"])
                                   Claim Id             File/Libs    Method Name     Stage             Timestamp Additional Details
    0  8d6bb524-c047-4aae-8597-b48ab467ef37  pandas, scikit-learn  uninstall_lib   Started  2022-07-13T11:46:55Z               None
    1  8d6bb524-c047-4aae-8597-b48ab467ef37  pandas, scikit-learn  uninstall_lib  Finished  2022-07-13T11:47:20Z               None
  • Verify if the specified libraries are uninstalled.
    >>> testenv.libs
               library version
    0           joblib   1.1.0
    1            numpy  1.21.6
    2              pip  20.1.1
    3  python-dateutil   2.8.2
    4             pytz  2022.1
    5            scipy   1.7.3
    6       setuptools  47.1.0
    7              six  1.16.0
    8    threadpoolctl   3.1.0

Example 3: Install and uninstall libraries specified in requirement text file asynchronously

  • Create a requirements.txt file with following contents.
    pandas
    joblib==0.13.2
    scikit-learn
    numpy>=1.17.1
    nltk>=3.3,<3.5
  • Install libraries specified in the file.
    >>> testenv.install_lib(libs_file_path="requirements.txt", asynchronous=True)
    Request to install libraries initiated successfully in the remote user environment testenv.
    Check the status using status() with the claim id 'c3669eea-327c-453f-b068-6b5f3f4768a5'.
  • Check the status.
    >>> testenv.status('c3669eea-327c-453f-b068-6b5f3f4768a5')
                                   Claim Id         File/Libs  Method Name     Stage             Timestamp Additional Details
    0  c3669eea-327c-453f-b068-6b5f3f4768a5  requirements.txt  install_lib   Started  2022-07-13T11:48:46Z               None
    1  c3669eea-327c-453f-b068-6b5f3f4768a5  requirements.txt  install_lib  Finished  2022-07-13T11:50:09Z               None
  • Verify libraries are installed along with dependent libraries.
    >>> testenv.libs
                library version
    0            joblib   1.1.0
    1             numpy  1.21.6
    2            pandas   1.3.5
    3               pip  20.1.1
    4   python-dateutil   2.8.2
    5              pytz  2022.1
    6      scikit-learn   1.0.2
    7             scipy   1.7.3
    8        setuptools  47.1.0
    9               six  1.16.0
    10    threadpoolctl   3.1.0
  • Uninstall libraries specified in the file asynchronously.
    >>> testenv.uninstall_lib(libs_file_path="requirements.txt", asynchronous=True)
    Request to uninstall libraries initiated successfully in the remote user environment testenv.
    Check the status using status() with the claim id '95ebfc7b-2910-4aab-be80-3e47f84737bd'.
  • Check the status.
    >>> testenv.status('95ebfc7b-2910-4aab-be80-3e47f84737bd')
                                   Claim Id         File/Libs    Method Name     Stage             Timestamp Additional Details
    0  95ebfc7b-2910-4aab-be80-3e47f84737bd  requirements.txt  uninstall_lib   Started  2022-07-13T11:52:03Z               None
    1  95ebfc7b-2910-4aab-be80-3e47f84737bd  requirements.txt  uninstall_lib  Finished  2022-07-13T11:52:39Z               None
  • Verify if the specified libraries are uninstalled.
    >>> testenv.libs
               library version
    0           joblib   1.1.0
    1            numpy  1.21.6
    2              pip  20.1.1
    3  python-dateutil   2.8.2
    4             pytz  2022.1
    5            scipy   1.7.3
    6       setuptools  47.1.0
    7              six  1.16.0
    8    threadpoolctl   3.1.0

Example 4: Install and uninstall libraries specified in requirement text file synchronously by specifying timeout

  • Create a requirement.txt file with following contents.
    matplotlib
  • Install libraries specified in the file.
    >>> testenv.install_lib(libs_file_path="requirements.txt")
                                   Claim Id         File/Libs  Method Name     Stage             Timestamp Additional Details
    0  d441bc45-6594-4244-ba26-de2ca3272d3f  requirements.txt  install_lib   Started  2022-08-12T06:03:54Z
    1  d441bc45-6594-4244-ba26-de2ca3272d3f  requirements.txt  install_lib  Finished  2022-08-12T06:04:44Z
  • Verify libraries are installed along with dependent libraries.
    >>> testenv.libs
                     name version
    0              cycler  0.11.0
    1           fonttools  4.34.4
    2          kiwisolver   1.4.4
    3          matplotlib   3.5.3
    4               numpy  1.21.6
    5           packaging    21.3
    6              Pillow   9.2.0
    7                 pip  20.1.1
    8           pyparsing   3.0.9
    9     python-dateutil   2.8.2
    10         setuptools  47.1.0
    11                six  1.16.0
    12  typing-extensions   4.3.0
  • Uninstall libraries specified in the file.
    >>> testenv.uninstall_lib(libs_file_path="requirements.txt", timeout=1)
    Request to uninstall libraries initiated successfully in the remote user environment 'testenv' but unable to get the status. Check the status using status() with the claim id '3e811857-969d-418c-893d-29ec38f54020'.
    '3e811857-969d-418c-893d-29ec38f54020'
  • Check the status.
    >>> testenv.status('3e811857-969d-418c-893d-29ec38f54020')
                                   Claim Id         File/Libs    Method Name     Stage             Timestamp Additional Details
    0  3e811857-969d-418c-893d-29ec38f54020  requirements.txt  uninstall_lib   Started  2022-08-12T06:05:51Z
    1  3e811857-969d-418c-893d-29ec38f54020  requirements.txt  uninstall_lib  Finished  2022-08-12T06:05:57Z
  • Verify if the specified libraries are uninstalled.
    >>> testenv.libs
                     name version
    0              cycler  0.11.0
    1           fonttools  4.34.4
    2          kiwisolver   1.4.4
    3               numpy  1.21.6
    4           packaging    21.3
    5              Pillow   9.2.0
    6                 pip  20.1.1
    7           pyparsing   3.0.9
    8     python-dateutil   2.8.2
    9          setuptools  47.1.0
    10                six  1.16.0
    11  typing-extensions   4.3.0

Examples for R environment

Example Prerequisite

Create remote R user environment for the following examples 5-8.

  • Create remote R user environment.
    >>> r_env = create_env('test_r_env', 'r_4.1', 'Test R environment')
    User environment 'test_r_env' created.
  • Install R libraries in the environment.
    >>> r_env.install_lib(['glm2', 'stringi', "lubridate", "zoo", "anytime", "plyr", "testthat", "dplyr"])
                                    Claim Id                                           File/Libs    Method Name    Stage               Timestamp    Additional Details
    0   6c7d049e-bf80-49a3-bee3-e058f78655fd    glm2, stringi, lubridate, zoo, anytime, plyr, ...   install_lib  Started    2023-09-12T09:30:14Z
    1   6c7d049e-bf80-49a3-bee3-e058f78655fd    glm2, stringi, lubridate, zoo, anytime, plyr, ...   install_lib Finished    2023-09-12T09:42:48Z
  • Verify installed libraries.
    >>> r_env.libs
              name  version
    0   KernSmooth  2.23-20
    1         MASS   7.3-55
    2       Matrix    1.4-0
    3         base    4.1.3
    ..         ...      ...
    33     anytime    0.3.9
    ..         ...      ...
    42       dplyr    1.1.3
    ..         ...      ...
    48        glm2    1.2.1
    ..         ...      ...
    52   lubridate    1.9.2
    ..         ...      ...
    57        plyr    1.8.8
    ..         ...      ...
    64     stringi   1.7.12
    65    testthat   3.1.10
    ..         ...      ...
    72       withr    2.5.0
    73         zoo   1.8-12

Example 5: Uninstall single R library synchronously

  • Uninstall the library.
    >>> r_env.uninstall_lib('glm2')
                                    Claim Id    File/Libs      Method Name     Stage               Timestamp    Additional Details
    0   f98cfbfd-8b1d-4ff8-8145-001a1e5b2009         glm2    uninstall_lib   Started    2023-09-12T10:14:59Z
    1   f98cfbfd-8b1d-4ff8-8145-001a1e5b2009         glm2    uninstall_lib  Finished    2023-09-12T10:15:01Z
  • Verify if the library is uninstalled.
    >>> r_env.libs
              name  version
    0   KernSmooth  2.23-20
    1         MASS   7.3-55
    2       Matrix    1.4-0
    3         base    4.1.3
    ..         ...      ...
    33     anytime    0.3.9
    ..         ...      ...
    42       dplyr    1.1.3
    ..         ...      ...
    51   lubridate    1.9.2
    ..         ...      ...
    56        plyr    1.8.8
    ..         ...      ...
    63     stringi   1.7.12
    64    testthat   3.1.10
    ..         ...      ...
    71       withr    2.5.0
    72         zoo   1.8-12

Example 7: Uninstall libraries specified in a requirement file synchronously

  • Create a requirement.json file with the following contents.
    {
        "packages": ["zoo", "anytime"]
    }
  • Uninstall libraries specified in the requirement file.
    >>> r_env.uninstall_lib(libs_file_path="requirement.json")
                                    Claim Id           File/Libs      Method Name      Stage               Timestamp    Additional Details
    0   7fbba8d7-7f16-47d1-b02d-b1df8a79ad6b    requirement.json    uninstall_lib    Started    2023-09-12T12:14:31Z
    1   7fbba8d7-7f16-47d1-b02d-b1df8a79ad6b    requirement.json    uninstall_lib   Finished    2023-09-12T12:14:33Z
  • Verify if the libraries are uninstalled.
    >>> r_env.libs
              name  version
    0   KernSmooth  2.23-20
    1         MASS   7.3-55
    2       Matrix    1.4-0
    3         base    4.1.3
    ..         ...      ...
    41       dplyr    1.1.3
    ..         ...      ...
    54        plyr    1.8.8
    ..         ...      ...
    61    testthat   3.1.10
    ..         ...      ...
    68       withr    2.5.0

Example 8: Uninstall R libraries asynchronously

  • Uninstall the libraries.
    >>> r_env.uninstall_lib(["plyr", "testthat"], asynchronous=True)
    Request to uninstall libraries initiated successfully in the remote user environment test_r_env. Check the status using status() with the claim id 'e6f90aaf-ecf5-467d-95cb-8032444494d6'.
    'e6f90aaf-ecf5-467d-95cb-8032444494d6'
  • Check the status using the claim id.
    >>> r_env.status('e6f90aaf-ecf5-467d-95cb-8032444494d6')
                                    Claim Id         File/Libs    Method Name      Stage               Timestamp    Additional Details
    0   e6f90aaf-ecf5-467d-95cb-8032444494d6    plyr, testthat  uninstall_lib    Started    2023-09-12T12:18:50Z
    1   e6f90aaf-ecf5-467d-95cb-8032444494d6    plyr, testthat  uninstall_lib   Finished    2023-09-12T12:18:51Z
  • Verify if the libraries are uninstalled.
    >>> r_env.libs
              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
    ..         ...      ...
    41       dplyr    1.1.3
    ..         ...      ...
    65       waldo    0.5.1
    66       withr    2.5.0

Example 9: Uninstall lib from conda environment

  • Create conda environment.
    >>> testenv_conda = create_env('testenv_conda', 'python_3.8', 'Test conda environment', conda_env=True)
    Conda environment creation initiated
    User environment 'testenv_conda' created.
  • View existing libraries installed.
    >>> testenv_conda.libs
                    name     version
    0      _libgcc_mutex         0.1
    1      _openmp_mutex         5.1
    2    ca-certificates  2023.12.12
    3   ld_impl_linux-64        2.38
    4             libffi       3.4.4
    5          libgcc-ng      11.2.0
    6            libgomp      11.2.0
    7       libstdcxx-ng      11.2.0
    8            ncurses         6.4
    9            openssl      3.0.12
    10               pip      23.3.1
    11            python      3.9.18
    12          readline         8.2
    13        setuptools      68.2.2
    14            sqlite      3.41.2
    15                tk      8.6.12
    16            tzdata       2023d
    17             wheel      0.41.2
    18                xz       5.4.5
    19              zlib      1.2.13
  • Install additional Python libraries.
    >>> testenv_conda.install_lib(['numpy','nltk>=3.3'])
                                   Claim Id   File/Libs/Model  Method Name     Stage             Timestamp Additional Details
    0  4e3d5cde-20fd-490f-981d-82fda578b2fd  numpy, nltk>=3.3  install_lib   Started  2024-01-31T17:56:15Z                  
    1  4e3d5cde-20fd-490f-981d-82fda578b2fd  numpy, nltk>=3.3  install_lib  Finished  2024-01-31T17:57:24Z   
  • List libraries installed.
    >>> testenv_conda.libs
                    name     version
    0      _libgcc_mutex         0.1
    1      _openmp_mutex         5.1
    2               blas         1.0
    3    ca-certificates  2023.12.12
    4              click       8.1.7
    5       intel-openmp    2023.1.0
    6             joblib       1.2.0
    7   ld_impl_linux-64        2.38
    8             libffi       3.4.4
    9          libgcc-ng      11.2.0
    10           libgomp      11.2.0
    11      libstdcxx-ng      11.2.0
    12               mkl    2023.1.0
    13       mkl-service       2.4.0
    14           mkl_fft       1.3.8
    15        mkl_random       1.2.4
    16           ncurses         6.4
    17              nltk       3.8.1
    18             numpy      1.26.3
    19        numpy-base      1.26.3
    20           openssl      3.0.12
    21               pip      23.3.1
    22            python      3.9.18
    23          readline         8.2
    24             regex   2023.10.3
    25        setuptools      68.2.2
    26            sqlite      3.41.2
    27               tbb    2021.8.0
    28                tk      8.6.12
    29              tqdm      4.65.0
    30            tzdata       2023d
    31             wheel      0.41.2
    32                xz       5.4.5
    33              zlib      1.2.13
  • Uninstall 'numpy' lib.
    >>> conda_env.uninstall_lib('numpy')
                                   Claim Id File/Libs/Model    Method Name     Stage             Timestamp Additional Details
    0  59b45390-7061-43b9-833f-489252da8ca0           numpy  uninstall_lib   Started  2024-01-31T18:02:57Z                  
    1  59b45390-7061-43b9-833f-489252da8ca0           numpy  uninstall_lib  Finished  2024-01-31T18:03:34Z