Indranil Sarkar
Indranil Sarkar

Reputation: 1

How to Resolve 'ModuleNotFoundError' When Running Python Script in Azure Runbook?

I have a python code kept at C drive which uses one Object.py for the below code in the Main.py script

Object.py has below code

class FileObject:
    def __init__(self, name, columns, thresholds, uniqueId):
        self.name = str(name).lower()
        self.columns = columns
        self.thresholds = thresholds
        self.uniqueId = uniqueId

Main.py has below reference

entitiesToProcess = [
    FileObject('csi_fa', ['CorporateName', 'TaxVatNumber','Full_Address'], [0.95, 0.95, 0.90], 'UIDFac')
    ]

Which works fine when I execute location through cmd. I have uploaded the Main.py script to azure runbook and now getting error I am directly using in runbook

class FileObject:
    def __init__(self, name, columns, thresholds, uniqueId):
        self.name = str(name).lower()
        self.columns = columns
        self.thresholds = thresholds
        self.uniqueId = uniqueId


entitiesToProcess = [
    FileObject('csi_fa', ['CorporateName', 'TaxVatNumber', 'Full_Address'], [0.95, 0.95, 0.90], 'UIDFac')
]
error : - line 7, in <module>    from Object import FileObjectModuleNotFoundError: No module named 'Object'

how do i solve

Upvotes: 0

Views: 254

Answers (1)

Jahnavi
Jahnavi

Reputation: 7818

I also received the same error when I tried in my environment firstly.

enter image description here

To resolve this,

Before importing the module, add the path of the directory containing the Object.py file to the sys.path list in runbook using sys.path.append().

import sys
sys.path.append('C:\\<path>\Object.py')
from Object import FileObject

After adding this to the code, it worked as expected.

enter image description here

Refer this documentation for the module search path.

Upvotes: 0

Related Questions