NameError: name 'azureml' is not defined

Viewed 49

I have to run both python and R code in azure ml notebook but since this is not working for me. So, I have made a import_dataframe.py file as:

import pandas
import subprocess
import sys

def read_df():
    subprocess.check_call([sys.executable, "-m", "pip", "install", azureml-core])
    from azureml.core import Dataset, Datastore
    from azureml.core import Workspace, Dataset

    subscription_id = 'abc'
    resource_group = 'pqr'
    workspace_name = 'xyz'

    workspace = Workspace(subscription_id, resource_group, workspace_name)
    datastore = Datastore.get(workspace, 'workspaceblobstore')
    # create tabular dataset from all parquet files in the directory
    tabular_dataset_3 = Dataset.Tabular.from_parquet_files(path=(datastore,'/UI/09-17-2022_125003_UTC/userdata1.parquet'))
    df=tabular_dataset_3.to_pandas_dataframe()
    return df

Now in the notebook with R kernel, I am using the following lines of code:

library(reticulate)
source_python("import_dataframe.py")
df <- read_df()

But I am getting the following error:

Error in py_call_impl(callable, dots$args, dots$keywords): NameError: name 'azureml' is not defined

Traceback:

1. read_df()
2. py_call_impl(callable, dots$args, dots$keywords)

Can anyone please help me to resolve this error ? Any help would be appreciated.

0 Answers
Related