4.8 Run Notebooks using different interpreters

An interpreter is a plug-in that allows you to use a specific data processing language backend. You select an interpreter by inserting its directive at the beginning of a notebook paragraph.

Topics:

4.8.1 Use the SQL Interpreter in a Notebook Paragraph

An Oracle Machine Learning notebook supports multiple languages. Each paragraph is associated with a specific interpreter. For example, to run SQL statements use the SQL interpreter. To run PL/SQL statements, use the script interpreter.

In an Oracle Machine Learning notebook, you can add multiple paragraphs, and each paragraph can be connected to different interpreters such as SQL or Python. You identify which interpreter to use by specifying % followed by the interpreter to use: sql, script, r, python, conda, markdown.

A paragraph has an input section and an output section. In the input section, specify the interpreter to run along with the text. This information is sent to the interpreter to be run. In the output section, the results of the interpreter are provided.
You can use the following directives in a notebook paragraph:
  • %sql: Supports standard SQL statements. In %sql the results of a SELECT statement are directly displayed in a table viewer, with access to other visualization options. Use the options in the chart settings to perform groupings, summation, and other operations.
  • %script: Supports both SQL statements and PL/SQL. In %script, the results of a SELECT statement are provided as text string output.
  • %conda: Supports the Conda environment. Type %conda at the beginning of the paragraph to connect to the Conda environment and work with third-party libraries for Python.
  • %r: Supports R scripts. Type %r at the beginning of the paragraph to connect to the R interpreter.
  • %python: Supports Python scripts. Type %python at the beginning of the paragraph to connect to the Python interpreter.
  • %md: Supports Markdown markup language.

Note:

To run a Group By on all your data, then it is recommended to use SQL scripts to do the grouping in the database, and return the summary information for charting in the notebook. Grouping at the notebook level works well for small sets of data. If you pull too much data to the notebook, you may encounter issues due to insufficient memory. You can set the row limit for your notebook by using the option Render Row Limit on the Connections Group page.
To fetch and visualize data in a notebook:
  1. On the Notebook page, click the notebook that you want to run.
    The notebook opens in edit mode.
  2. Type %SQL to call the SQL interpreter, and press Enter. Your notebook is now ready to run SQL statements.
  3. Type the SQL statement to fetch data from an Oracle AI Database. For example, type SELECT * FROM TABLENAME and click run icon. Alternatively, press Shift+Enter keys to run the notebook.

    Note:

    Notebooks must be opened as a regular user, that is, a non-administrator user. The Run notebook option is not available to the Administrator.
    This fetches the data in the notebook.
  4. The data is displayed in the output of the paragraph.
    The results of the interpreter appear in the output section. The output section of the paragraph comprises a charting component that displays the results in graphical output. The chart interface allows you to interact with the output in the notebook paragraph. You have the option to run and edit single a paragraph or all paragraphs in a notebook.
    For Table Options, click settings and select:
    • useFilter: To enable filter for columns.

    • showPagination: To enable pagination for enhanced navigation.

    • showAggregationFooter: To enable a footer to display aggregated values.

    You can also sort the columns by clicking the down arrow next to the column name.

    To visualize the tabular data, click the respective icons for each of the each graphical representation, as shown here:
    • Click Bar Chart to represent the data in a Bar Chart.
    • Click Pie Chart to represent the data in a Pie Chart.
    • Click Area Chart to represent the data in an Area Chart.
    • Click Line Chart to represent the data in a Line Chart.
    • Click Scatter Chart to represent the data in a Scatter Chart.

4.8.1.1 About Oracle Machine Learning for SQL

Oracle Machine Learning for SQL (OML4SQL) provides a powerful, state-of-the-art machine learning capability within Oracle AI Database. You can use Oracle Machine Learning for SQL to build and deploy predictive and descriptive machine learning models, add intelligent capabilities to existing and new applications.

Oracle Machine Learning for SQL offers an extensive set of in-database algorithms for performing a variety of machine learning tasks, such as classification, regression, anomaly detection, feature extraction, clustering, and market basket analysis, among others. The programmatic interfaces to OML4SQL are PL/SQL for building and maintaining models and a family of SQL functions for scoring.

Use Oracle Machine Learning Notebooks with the SQL and PL/SQL interpreters to run SQL statements (%sql) and PL/SQL scripts (%script) respectively. Use Oracle Machine Learning for SQL to:
  • Perform data exploration and data analysis
  • Build, evaluate and deploy machine learning models, and
  • Score data using those models

4.8.1.2 Set Output Format in Notebooks

Oracle Machine Learning Notebooks allow you to preformat query output in notebooks.

To preformat query output, you must use the command SET SQLFORMAT as follows:
  1. Open a notebook in Oracle Machine Learning.
  2. Type the command:
    %script
    SET SQLFORMAT format_option
    For example, if you want the output in ansiconsole format, then type the command followed by the SQL query as:
    SET SQLFORMAT ansiconsole;
    SELECT * FROM HR.EMPLOYEES;
    Here, the output format is ansiconsole, and the table name is HR.EMPLOYEES.

    Note:

    This formatting is available for the Script interpreter. Therefore, you must add the prefix %script as shown in this example.

4.8.1.3 Output Formats Supported by SET SQLFORMAT Command

By using the SET SQLFORMAT command, you can generate the query output in a variety for formats.

Note:

These output formats are available for the Script interpreter. Therefore, you must include the prefix %script.
The available output formats are:
  • CSV: The CSV format produces standard comma-separated variable output, with string values enclosed in double quotes. The syntax is:

    %script

    SET SQLFORMAT CSV

  • HTML: The HTML format produces the HTML for a responsive table. The content of the table changes dynamically to match the search string entered in the text field. The syntax is:

    %script

    SET SQLFORMAT HTML

  • XML: The XML format produces a tag based XML document. All data is presented as CDATA tags. The syntax is:

    %script

    SET SQLFORMAT XML

  • JSON: The JSON format produces a JSON document containing the definitions of the columns along with the data that it contains. The syntax is:

    %script

    SET SQLFORMAT JSON

  • ANSICONSOLE: The ANSICONSOLE format resizes the columns to the width of the data to save space. It also underlines the columns, instead of separate line of output. The syntax is:

    %script

    SET SQLFORMAT ANSICONSOLE

  • INSERT: The INSERT format produces the INSERT statements that could be used to recreate the rows in a table. The syntax is:

    %script

    SET SQLFORMAT INSERT

  • LOADER: The LOADER format produces pipe delimited output with string values enclosed in double quotes. The column names are not included in the output. The syntax is:

    %script

    SET SQLFORMAT LOADER

  • FIXED: The FIXED format produces fixed width columns with all data enclosed in double-quotes. The syntax is:

    %script

    SET SQLFORMAT FIXED

  • DEFAULT: The DEFAULT option clears all previous SQLFORMAT settings, and returns to the default output. The syntax is:

    %script

    SET SQLFORMAT DEFAULT

    Note:

    You can also run this command without the format name DEFAULT by simply typing SET SQLFORMAT.
  • DELIMITED: The DELIMITED format allows you to manually define the delimiter string, and the characters that are enclosed in the string values. The syntax is:

    %script

    SQLFORMAT DELIMITED delimiter left_enclosure right_enclosure

    For example,

    %script

    SET SQLFORMAT DELIMITED ~del~ " "

    SELECT * FROM emp WHERE deptno = 20;

    Output:

    "EMPNO"~del~"ENAME"~del~"JOB"~del~"MGR"~del~"HIREDATE"~del~"SAL"~del~"COMM"~del~"DEPTNO"

    In this example, the delimiter string is ~del~ and string values such as EMPNO, ENAME, JOB and so on, are enclosed in double quotes.

4.8.2 Use the Python Interpreter in a Notebook Paragraph

An Oracle Machine Learning notebook supports multiple languages. Each paragraph is associated with a specific interpreter. To run Python commands in a notebook, you must first connect to the Python interpreter. To use OML4Py, you must import the oml module.

In an Oracle Machine Learning notebook, you can add multiple paragraphs, and each paragraph can be connected to different interpreters such as SQL or Python. You identify which interpreter to use by specifying % followed by the interpreter to use: sql, script, r, python, conda, markdown.

This example shows you how to:
  • Connect to a Python interpreter to run Python commands in a notebook
  • Import the Python modules - oml, matplotlib, and numpy
  • Check if the oml module is connected to the Oracle AI Database

Note:

z is a reserved keyword and must not be used as a variable in %python paragraphs in Oracle Machine Learning notebooks.
Assumption: The example assumes that you have created a new notebook named Py Note.
  1. Open the Py Note notebook and click the interpreter bindings icon. View the available interpreter bindings.
  2. To connect to the Python interpreter, type %python
    You are now ready to run Python scripts in your notebook.
  3. To use OML4Py module, you must import the oml module. Type the following Python command to import the oml module, and the click run icon. Alternatively, you can press Shift+Enter keys to run the notebook.
    import oml
  4. To verify if the oml module is connected to the Database, type:
    oml.isconnected()
    Once your notebook is connected, the command returns TRUE. The notebook is now connected to the Python interpreter, and you are ready to run python commands in your notebook.

Example to demonstrate the use of the Python modules - matplotlib and numpy , and use random data to plot two histograms.

  1. Type the following commands to import the modules:
    %python
    import matplotlib.pyplot as plt
    import numpy as np
    • Matplotlib - Python module to render graphs
    • Numpy - Python module for computations
  2. Type the following commands to compute and render the data in two histograms.
    
    list1 = np.random.rand(10)*2.1
    list2 = np.random.rand(10)*3.0
    
    plt.subplot(1,2,1) # 1 line, 2 rows, index nr 1 (first position in the subplot)
    plt.hist(list1)
    plt.subplot(1, 2, 2) # 1 line, 2 rows, index nr 2 (second position in the subplot)
    plt.hist(list2)
    plt.show()
    In this example, the commands import two Python module to compute and render the data in two histograms list1 and list2.
  3. Click Run.
    The output section of the paragraph which contains a charting component displays the results in two histograms - list1 and list2, as shown in the screenshot.

4.8.2.1 About Oracle Machine Learning for Python

Oracle Machine Learning for Python (OML4Py) is a component of Oracle Autonomous AI Database, which includes Oracle Autonomous AI Lakehouse (ADW), Oracle Autonomous AI Transaction Processing (ATP), and Oracle Autonomous AI JSON Database (AJD). By using Oracle Machine Learning UI notebooks, you can run Python functions on data for data exploration and preparation while leveraging Oracle AI Database as a high-performance computing environment. Oracle Machine Learning User Interface (UI) is available through Autonomous AI Lakehouse (ADW) , Autonomous AI Transaction Processing (ATP) and Autonomous AI JSON Database (AJD) services.

Oracle Machine Learning for Python (OML4Py) makes the open source Python scripting language and environment ready for the enterprise and big data. Designed for problems involving both large and small volumes of data, Oracle Machine Learning for Python integrates Python with Oracle Autonomous AI Database, including its powerful in-database machine learning algorithms, and enables deployment of Python code.

Use Oracle Machine Learning for Python to:
  • Perform data exploration, data analysis, and machine learning using Python leveraging Oracle AI Database as a high performance compute engine
  • Build and evaluate machine learning models and score data using those models from an integrated Python API using in-database algorithms
  • Deploy user-defined Python functions through a REST interface with data-parallel and task-parallel processing

The Python interpreter uses Python 3.13.5 to process Python scripts in Oracle Machine Learning notebooks. To use the interpreter, specify the %python directive at the beginning of the paragraph. The Python interpreter supports the following Python modules:

  • cffi-1.15.1
  • contourpy-1.1.0
  • cryptography-43.0.1
  • cycler-0.10.0
  • fonttools-4.49.0
  • joblib-1.4.2
  • kiwisolver-1.4.5
  • matplotlib-3.8.4
  • numpy-2.0.1
  • oracledb-2.4.1
  • packaging-23.1
  • pandas-2.2.2
  • pillow-10.4.0
  • pycparser-2.21
  • pyparsing-2.4.0
  • python_dateutil-2.8.2
  • pytz-2022.1
  • scikit_learn-1.5.1
  • scipy-1.14.0
  • setuptools-70.0.0
  • six-1.16.0
  • threadpoolctl-3.5.0

4.8.3 Use the R Interpreter in a Notebook Paragraph

An Oracle Machine Learning notebook supports multiple languages. Each paragraph is associated with a specific interpreter. To run R functions in an Oracle Machine Learning notebook, you must first connect to the R interpreter.

In an Oracle Machine Learning notebook, you can add multiple paragraphs, and each paragraph can be connected to different interpreters such as R or SQL or Python. You identify which interpreter to use by specifying % followed by the interpreter to use: sql, script, r, python, conda, markdown.

This example shows how to:
  • Connect to the R interpreter to run R commands in a notebook.
  • Verify the connection to Oracle Autonomous AI Database, and
  • Load the ORE libraries
  1. To connect to the R interpreter, type the following directive at the beginning of the notebook paragraph, and press Enter:
    %r
  2. To verify the database connection, type the following command and press Enter:
    ore.is.connected()
    Once your notebook is connected, the command returns TRUE, as shown in the screenshot here. The notebook is now connected to the R interpreter, and you are ready to run R commands in your notebook.

    Figure 4-90 Command to Test Database Connection



  3. To import R Libraries, run the following commands:
    library(ORE)
    library(OREdplyr)
    Once the packages are loaded successfully, the list of ORE packages are displayed as shown in the screenshot here. Scroll down to view the entire list.

    Figure 4-91 Command to Import R packages



4.8.3.1 About Oracle Machine Learning for R

Oracle Machine Learning for R (OML4R) is a component of the Oracle Machine Learning family of products, which integrates R with Oracle Autonomous AI Database.

Oracle Machine Learning for R makes the open source R scripting language and environment ready for enterprise and big data. It is designed for problems involving for both large and small data volumes. OML4R allows users to run R commands and scripts for statistical, machine learning, and perform visualization analyses on database tables and views using R syntax.

Oracle Machine Learning for R is available in Oracle Machine Learning UI, currently available through Oracle Autonomous AI Database, including Autonomous AI Lakehouse, Autonomous AI Transaction Processing, and Autonomous AI JSON Database. Oracle Machine Learning for R Embedded R Execution functionality can be deployed through SQL and REST APIs on Autonomous AI Database.

Use Oracle Machine Learning for R to:

  • Perform data exploration and data preparation while seamlessly leveraging as a high-performance computing environment.
  • Run user-defined R functions on database spawned and controlled R engines, with system-supported data-parallel and task-parallel capabilities.
  • Access and use powerful in-database machine learning algorithms from R language.

To use the R interpreter, specify the %r directive at the beginning of the paragraph. The following R packages are installed to support Oracle Machine Learning for R.

Supported Oracle Machine Learning for R Proprietary R Packages

The supported Oracle Machine Learning for R proprietary R packages are:

  • ORE_1.5.1
  • OREbase_1.5.1
  • OREcommon_1.5.1
  • OREdm_1.5.1
  • OREdplyr_1.5.1
  • OREeda_1.5.1
  • OREembed_1.5.1
  • OREgraphics_1.5.1
  • OREmodels_1.5.1
  • OREpredict_1.5.1
  • OREstats_1.5.1
  • ORExml_1.5.1

Supported Open Source R Modules

The following open source R packages are supported by Oracle Machine Learning for R:

  • R-4.0.5
  • Cairo_1.5-15
  • ROracle_1.4-1: DBI_1.1-2
  • arules_1.7-3
  • png_0.1-7
  • randomForest_4.6-14
  • statmod_1.4-36
  • dplyr_1.0-9:
  • R6_2.5.1
  • assertthat_0.2.1
  • cli_3.3.0
  • crayon_1.5.1
  • ellipsis_0.3.2
  • fansi_1.0.3
  • generics_0.1.2
  • glue_1.6.2
  • lazyeval_0.2.2
  • lifecycle_1.0.1
  • magrittr_2.0.3
  • pillar_1.7.0
  • pkgconfig_2.0.3
  • purrr_0.3.4
  • rlang_1.0.2
  • tibble_3.1.7
  • tidyselect_1.1.2
  • utf8_1.2.2
  • vctrs_0.4.1

Oracle Machine Learning for R Interpreter Requirements

The R interpreter requires the following open source R packages:
  • Rkernel 1.3:
    • base64enc 0.1-3
    • cli 3.3.0
    • crayon 1.5.1
    • digest 0.6.29
    • ellipsis 0.3.2
    • evaluate 0.15
    • fansi 1.0.3
    • fastmap 1.1.0
    • glue 1.6.2
    • htmltools 0.5.2
    • IRdisplay 1.1
    • jsonlite 1.8.0
    • lifecycle 1.0.1
    • pbdZMQ 0.3-7
    • pillar 1.7.0
    • repr 1.1.4
    • rlang 1.0.2
    • utf8 1.2.2
    • uuid 1.1-0
    • vctrs 0.4.1
  • knitr 1.39:
    • evaluate_0.15
    • glue_1.6.2
    • highr_0.9
    • magrittr_2.0.3
    • stringi_1.7.6
    • stringr_1.4.0
    • xfun_0.31
    • yaml_2.3.5

4.8.4 Use the Conda Interpreter in a Notebook Paragraph

Oracle Machine Learning Notebooks provides a Conda interpreter to enable administrators to create conda environments with custom third-party Python and R libraries. Once created, you can download and activate Conda environments inside a notebook session also using the Conda interpreter.

An Oracle Machine Learning notebook supports multiple languages. For this, you must create a notebook with some paragraphs to run SQL queries, and other paragraphs to run PL/SQL scripts. To run a notebook in different scripting languages, you must first connect the notebook paragraphs with the respective interpreters such as SQL, PL/SQL, R, Python, or Conda.

This topic shows how to start working in the Conda environment:
  • Connect to the Conda interpreter
  • Download and activate the Conda environment
  • View the list of packages in the Conda environment
  • Run a Python function to import the Iris dataset, and use the seaborn package for visualization
  1. Type %conda at the beginning of the paragraph to connect to the Conda interpreter, and press Enter.
    %conda
  2. Next, download and activate the Conda environment. Type:
    download sbenv
    activate sbenv
    In this example, the Conda environment is downloaded and activated. The name of the Conda environment in this example is sbenv.Download and Activate the Conda Environment
  3. You can view all the packages that are present in the Conda environment. To view the list of packages, type list.
    List of packages in the seaborn library
  4. Here's an example that demonstrates how to use the seaborn library package for visualization. Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing attractive statistical graphics. This example
    • Imports Pandas and seaborn
    • Loads the Iris dataset
    • Plots the datapoints, that is, the three different species of the Iris flower - Setosa, Virginica, and Versicolor based on its dimensions. It creates a scatter plot
    Type:
    %python
    
    def sb_plot():
        import pandas as pd
        import seaborn as sb
        from matplotlib import pyplot as plt
        df = sb.load_dataset('iris')
        sb.set_style("ticks")
        sb.pairplot(df,hue = 'species',diag_kind = "kde",kind = "scatter",palette = "husl")
        plt.show()
    Commands
  5. Run the function in a Python paragraph.
    Type:
    %python 
    sb_plot()
    Visualization using Seaborn Python library

4.8.4.1 About the Conda Environment and Conda Interpreter

Conda is an open-source package and environment management system that allows the use of environments containing third-party Python and R libraries. Oracle Machine Learning User Interface (UI) provide the conda interpreter to install third-party Python and R libraries inside a notebook session.

Third-party libraries installed in Oracle Machine Learning Notebooks can be used in:
  • Standard Python
  • Standard R
  • Oracle Machine Learning for Python embedded Python execution from the Python, SQL and REST APIs
  • Oracle Machine Learning for R embedded R execution from the R, SQL, and REST APIs

To start working in the Conda environment:

  1. Ensure that a Conda environment is saved to Object Storage, or update an existing package by installing a new version.

    Note:

    You must be signed in as ADMIN user to create the Conda environment. The administrator manages the lifecycle of an environment, including adding or deleting packages from it, and removing environments. The Conda environments are stored in an Object Storage bucket associated with the Autonomous AI Database.
  2. Sign into Oracle Machine Learning UI and download the Conda environment. To download the Conda environment, type:
    %conda 
    download myenv
  3. Activate the Conda environment. To activate the Conda environment, type:
    activate myenv

    Note:

    There is only one active Conda environment at a given point in time.
  4. Create a notebook, use the Conda interpreter to use third-party libraries in the Object Storage. To use the Conda interpreter, type %conda at the beginning of the paragraph to connect to the Conda environment, and work with third-party libraries for Python. You can switch between the preinstalled Conda environments. For example, you can have an environment for working with Graph analysis, and another environment for Oracle Machine Learning analysis.
  5. Deactivate the Conda environment. As a best practice, deactivate the Conda environment after you have finished working on your machine learning analysis. To deactivate the environment, type:
    deactivate

4.8.4.2 Conda Interpreter Commands

This table lists the commands for the Conda interpreter.

Conda Interpreter Commands

Table 4-1 Conda Interpreter Commands

Tasks Commands Role
Create a Conda environment. create -n <env_name> <python_version>
  • ADMIN
Remove a list of packages from a specified conda environment. It is also an alias for conda uninstall. remove -n <env_name> --all

Note:

The Conda environment is deleted from the user session.
  • ADMIN
  • OML user
List user-created local environment. env list
  • ADMIN
  • OML user
Remove user-created local environment. env remove -n <env_name>
  • ADMIN
  • OML user
List all packages and versions installed in active environment. list
  • ADMIN
  • OML user
Activate a user-created local environment. activate -n <env_name>
  • ADMIN
  • OML user
Deactivate the current environment. deactivate
  • ADMIN
  • OML user
Install an external package from a public Conda channel. install -n <env_name> <package_name>
  • ADMIN
Uninstall a specific package from a Conda environment. It is also an alias for remove. uninstall -n <env_name> <package_name>
  • ADMIN
Display information about current conda install. info
  • ADMIN
  • OML user
View the command line help. COMMANDNAME --help
  • ADMIN
  • OML user
Upload a Conda environment to object storage.

Note:

This is an Oracle Autonomous AI Database specific command.
upload --overwrite <env_name> --description 'some description' -t <name> <value>

Note:

You can provide many tags. For example: -t <name1> <value1> -t <name2> <value2> ..
  • ADMIN
Download and unpack a specific Conda environment from the object storage.

Note:

This is an Oracle Autonomous AI Database specific command.
download --overwrite <env_name>
  • ADMIN
  • OML user
List local environments available to the user. list-local-envs
  • ADMIN
  • OML user
List all Conda environments in the object storage.

Note:

This is an Oracle Autonomous AI Database specific command.
list-saved-envs --installed-packages -e <env_name>
  • ADMIN
  • OML user
Delete a Conda environment.

Note:

This is an Oracle Autonomous AI Database specific command.
delete <env_name>

Note:

The Conda environment is deleted from the Object Storage.
  • ADMIN
Update conda packages to the latest compatible version. update
  • ADMIN
Upgrade the current conda package. It is also an alias for conda update. upgrade
  • ADMIN
Search for packages and display associated information. The input is a MatchSpec, a query language for conda packages. search
  • ADMIN
  • OML user

4.8.4.3 Create a Conda Environment for Python, Install a Python Package and Upload it to Object Storage

This topic demonstrates how to create a Conda environment mypyenv for Python packages, with Python 3.13.5 that is compatible with OML4Py. Here, you will also install the Python package seaborn from the conda-forge channel, and upload the Conda environment mypyenv to object storage.

Conda channels are the locations where packages are stored. They serve as the base for hosting and managing packages. Conda packages are downloaded from remote channels, which are URLs to directories containing conda packages. The conda command searches a set of channels. By default, packages are automatically downloaded and updated from the default channel. The conda-forge channel is a community channel made up of thousands of contributors, and is free for all to use. You can modify what remote channels are automatically searched. You might want to do this to maintain a private or internal channel.

Note:

You must be signed in as ADMIN user to create the Conda environment.

Note:

To avoid version conflicts, please do not install packages that are already included in OML4Py. For a complete list of pre-installed packages and their versions, see Python Libraries in OML4Py.
To create a Conda environment:
  1. Run the following command to list the environments that are available by default. Conda contains default environments with some core system libraries and conda dependencies. Run the following command to list the available environments.
    %conda
    
    env list

    Note:

    The active environment is marked with an asterisk (*).
    The command returns the list of following environments:

    Figure 4-92 Command to list Conda environments



  2. Now, run the following command to create an environment by the name mypyenv from the conda-forge channel, install the Python package seaborn, and upload the conda environment mypyenv to Object Storage:
    %conda
    
    create -n mypyenv -c conda-forge --override-channels --strict-channel-priority python=3.13.5 seaborn
    
    upload mypyenv --overwrite -t application "OML4PY"

    Note:

    This example uses Python version 3.13.5. You must ensure compatibility between the third-party package version and the Python version that OML4Py uses.
    To determine the Python version being used, run the following command:
    import sys
    sys.version
    In this command:
    • -n: This is the name of the environment. In this example, it is mypyenv.
    • -c: This is the channel name. In this example, the conda-forgechannel is used to install the Python package.
    • --override-channels: This argument ensures that the system does not search default, and requires a channel to be mentioned.
    • --strict-channel-priority: This argument ensures that packages in lower priority channels are not considered if a package with the same name appears in a higher priority channel. In this example, the priority is given to Python 3.13.5 and seaborn.
    • upload: This argument uploads the Conda environment named mypyenv to a target location.
    • --overwrite: This argument ensures that if a file or directory with the same name already exists at the target location, it should be overwritten.
    • -t application: This argument specifies the type of the target as an application.
    • "OML4PY": This is the name or path of the target application where the environment will be uploaded.
    The command returns the following message once it creates the environment and installs the listed package. Scroll down the paragraph to view the complete details.

    Figure 4-93 Command to create a Conda environment



  3. Now, verify the environment that you created. Run the following command once again to view the list of environments.
    %conda
    
    env list

    Note:

    The mypyenv environment is not yet active. The active environment is marked with an asterisk (*), and in this list, it is present against the base environment usr.
    Note that the environment mypyenv is listed in the output.

    Figure 4-94 mypyenv environment created



  4. To activate the environment mypyenv, run the following command:
    %conda
    
    activate mypyenv

    Figure 4-95 Command to activate Conda environment



  5. Now, run the command to list the environment once again to view the list of active environments. Note that the asterisk (*) is now present against the mypyenv environment.

    Figure 4-96 Activated environment mypyenv listed



The asterisk (*) next to the environment name confirms the activation. This completes the task of creating, activating and verifying a Conda environment.

4.8.4.4 Create a Conda Environment for R and Install R Package and Upload it to Object Storage

This topic shows how to create a Conda environment myrenv for R packages, with R-4.0.5 for OML4R compatibility, install the forecast package, and upload the Conda environment to object storage.

Note:

You must be signed in as ADMIN user to create the Conda environment.

Note:

To avoid version conflicts, please do not install packages that are already included in OML4R. For a complete list of pre-installed packages and their versions, see About the OML4R Supporting Packages
To create a Conda environment named myrenv with R-4.0.5 for OML4R compatibility, install the package forecast, and upload the Conda environment myrenv to object storage:
  1. Run the following command to create the environment for R by the name myrenv, install the package forecast and upload the Conda environment myrenv to object storage:
    %conda
    
    create -n myrenv -c conda-forge --override-channels --strict-channel-priority r-base=4.0.5 r-forecast
    
    upload myrenv --overwrite -t application "OML4R"

    Note:

    In this example, we are using the conda-forge channel to install the R packages.
    In this command:
    • -n: This is the name of the environment. In this example, it is myrenv.
    • -c: This is the channel name. In this example, it is conda-forge.
    • --override-channels: This argument ensures that the system does not search default, and requires a channel to be mentioned.
    • --strict-channel-priority: This argument ensures that packages in lower priority channels are not considered if a package with the same name appears in a higher priority channel. In this example, the priority is given to R-4.0.5 and forecast.
    • upload: This argument uploads the Conda environment named myrenv to a target location.
    • --overwrite: This argument ensures that if a file or directory with the same name already exists at the target location, it should be overwritten.
    • -t application: This argument specifies the type of the target as an application.
    • "OML4R": This is the name or path of the target application where the environment will be uploaded.
    The command returns the following:

    Figure 4-97 Command to create Conda environment for R and install R Packages



  2. You may now verify the Conda environment for R that you just created. Run the following command in a %conda paragraph to view the list of environments.
    env list
    Note that the myrenv environment is now listed along with the mypyenv in the output.

    Figure 4-98 myrenv environment created and listed



    Note that the asterisk (*) is against the mypyenv, indicating that this environment is active currently.

4.8.4.5 Upload the Conda environments to an Object Storage bucket associated with the Autonomous AI Database

There is one Object Storage bucket for each data center region. The Conda environment is saved to a folder in Object Storage corresponding to the tenancy and database. The folder is managed by Autonomous AI Database and is only available to users through Oracle Machine Learning Notebooks. There is an 8G maximum size for a single Conda environment, and no size limit on Object Storage.

This topic shows how to upload a Conda environment to the Object Storage bucket associated with the Autonomous AI Database instance using the upload command. You will provide environment descriptions and tags, one for the user name and one for the application name. You will also overwrite any environment with the same name if it exists. The application tag is required for use with embedded execution. For example, OML4Py embedded Python execution works with Conda environments containing the OML4PY tag.
To upload a Conda environment to the Object Storage bucket:
  1. In a Conda paragraph in your notebook, run the following command to upload the mypyenv to the Object Storage bucket associated with the Autonomous AI Database.
    upload mypyenv --overwrite --description 'Install Python seaborn and tensorflow packages' -t user 'OMLUSER' -t application OML4PY
    In this command, you use the upload command and provide the following:
    • --description: a description of your task.
    • -t: A tag for the user OMLUSER and for the application OML4PY.

    Figure 4-99 Command to load the Conda environment for Py


    Command to load the Conda environment for Py

  2. Now, run the following command to view the list of saved environments in mypyenv:
    list-saved-envs -e mypyenv
    The command returns the following:

    Figure 4-100 View saved environment mypyenv


    View saved environment mypyenv

  3. Now upload the myrenv to the object storage by running the following command in a Conda paragraph:
    %conda
    
    upload myrenv --overwrite --description 'Install R forecast and ggplot2 packages' -t user 'OMLUSER' -t application 'OML4R
    The command returns the following:

    Figure 4-101 Command to upload Conda environment for R


    Command to upload Conda environment for R to Object Storage

  4. Again, run the following command to view the list of saved environments in myrenv:
    %conda
    
    list-saved-envs -e myrenv
    The command returns the following:

    Figure 4-102 View saved environment myrenv


    View saved environment myrenv

This completes the task of uploading the Python and R environments mypyenv and myrenv to the Object Storage associated with the Autonomous AI Database. The environments are now available for you to download and use. The environments will remain in the Object Storage until it is deleted.

4.8.5 Use the Markdown Interpreter and Generate Static html from Markdown Plain Text

Use the Markdown interpreter and generate static html from Markdown plain text.

To call the Markdown interpreter and generate static html from Markdown plain text:
  1. In your notebook, type %md and press Enter.
  2. Type "Hello World!" and click Run. The static html text is generated, as seen in the screenshot below.
    Static html text
  3. You can format the text in bold. To display the text in bold, write the same text inside two asterisks pair and click Run.
    Text in bold
  4. To display the text in italics, write the same text inside an asterisk pair or underscore pair as shown in the screenshot, and click Run.
    Text in italics
  5. To display the text in a bulleted list, prefix *(asterisk) to the text, as shown in the screenshot below:
    Text in bulleted points
  6. To display the text in heading1, heading 2 and heading 2, prefix # (hash) to the text and click Run. For H1, H2, and H3, you must prefix one, two, and three hashes respectively.
    Headings