import matplotlib failed while deploying my model in AWS sagemaker
I have deployed my AWS model successfully.
but while testing i am getting runtime Error: &quot;import matplotlib.pyplot as plt&quot; . I think it is due to pytorch framework version i used(framework_version=1.2.0). I am facing the same issue when i use higher versions as well.
PyTorchModel(model_data=model_artifact,
                 role = role,
                 framework_version=1.2.0,
                 entry_point='predict.py',
                 predictor_cls=ImagePredictor)

I have other issue when i use version=1.0.0. i.e i am not able to import libraries from sub directories and deployment itself is failing.
Eg: i have some code files in &quot;Code&quot; directory.
 from Code.CTModel import NetWork  ---&gt; **this line will fail as &quot;No module named Code&quot; when i use version=1.0.0**

Ultimately i want to how to use/import libraries which are written under sub-directories.

It sounds like you want to inject some additional code libraries into the SageMaker PyTorch serving container. You might have to dig into the source code for how the PyTorch serving container is built to further customize it: https://github.com/aws/sagemaker-pytorch-inference-toolkit, or build your own image.
Digging into that source code a bit, I see that the container has enabled the importing of arbitrary code, but only when &quot;multi-model mode&quot; is enabled. Can you verify that the code exists under a directory &quot;code&quot; in your model directory and that &quot;multi-model mode&quot; is enabled?
    def initialize(self, context):
        # Adding the 'code' directory path to sys.path to allow importing user modules when multi-model mode is enabled.
        if (not self._initialized) and ENABLE_MULTI_MODEL:
            code_dir = os.path.join(context.system_properties.get(&quot;model_dir&quot;), 'code')
            sys.path.append(code_dir)
            self._initialized = True

Reference: https://github.com/aws/sagemaker-pytorch-inference-toolkit/blob/c4e7abc49aeebc2f9b6035337548a90e4330113d/src/sagemaker_pytorch_serving_container/handler_service.py#L47
If this all seems complicated to you (it is), you might want to look into some standardized formats for serializing your PyTorch model such as https://onnx.ai/. I'd love to learn more about what you're trying to do here sometime if you reach out to me at contact@modelzoo.dev. I'm beta-testing a platform that enables deployment in a single line of code and would love to test it out here.
