0

I have the below score.py file I trying to deploy using Azure ACI. The issue is Im getting module not found error indicating my python cleaning script ('cpp_data_prep_methods') cannot be found even though I have the score.py and pyhthon script in same folder.

My python script is also reading a csv file that is also found in same folder. My question is, Is it possible to call a personally written cleaning script inside score.py? Below shows how I'm calling my script (cpp_data_prep_methods )

import joblib
import os
import pandas as pd
import json
import numpy as np
from azureml.core import Workspace, workspace
import yaml
import sys
#sys.path.append(os.path.abspath(os.path.join('..')))
from cpp_data_prep_methods import *
import warnings
warnings.filterwarnings("ignore")


def init():
    global model
    model_path = Model.get_model_path(
        model_name="test_model.pkl")
    model = joblib.load(model_path)

init()

def run(raw_data):
    try:
        data = json.loads(raw_data)["data"]
      
        # Clean Data using my cleaning script with csv and txt files inside.
        data = cpp_all_data_prep(data, verbose=False)

        new_data = np.array(data)

        result = model.predict(new_data)
        return result.tolist()
    except Exception as e:
        error = str(e)
        return error```
masterp
  • 11
  • 3

1 Answers1

0

I can understand that the issue with your script is while importing your common script.

So as per your statement I’ve noticed that you are getting Module Not Found Error while importing your script. This will usually work if we have both the files in the same folder, we will get module not found error either imported script is not in the same folder or it is not a python file (A file without .py as extension)

As below I am importing test1.txt in init.py file:

enter image description here

My code as below:

enter image description here

As the test1 file is a text file, I got ModuleNotFoundError. Now I’ll be saving it to test1.py

enter image description here

My code execution and output as below:

enter image description here

Try to import the complete file after converting into .py

VenkateshDodda
  • 4,723
  • 1
  • 3
  • 12
SaiKarri-MT
  • 1,174
  • 1
  • 3
  • 8