VM Environment Fails Because It Cannot Find ipkernal Module

Gregory Jacobs 11 Reputation points
2021-04-16T03:57:35.163+00:00

I have created a python script using Azure SDK to train a machine learning model and save an output .csv file. I created a python environment with all of the conda and pip dependencies needed to run the script and registered that environment to the workspace. However, when I go to run my script using the registered environment my experiments keep failing. The error message in the log that I cannot figure out states that the script fails because it cannot find the 'ipykernal' module when trying to import matplotlib. Here is the full text of error message:

[2021-04-15T22:52:41.716160] The experiment failed. Finalizing run...
[2021-04-15T22:52:41.716178] Start FinalizingInRunHistory
[2021-04-15T22:52:41.717507] Logging experiment finalizing status in history service.
Starting the daemon thread to refresh tokens in background for process with pid = 22305
Cleaning up all outstanding Run operations, waiting 300.0 seconds
1 items cleaning up...
Cleanup took 0.07227706909179688 seconds
Traceback (most recent call last):
File "prod_model.py", line 5, in <module>
import matplotlib.pyplot as plt
File "/home/azureuser/.azureml/envs/azureml_1525a6aa7633563e0d590fe86701d51d/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2356, in <module>
switch_backend(rcParams["backend"])
File "/home/azureuser/.azureml/envs/azureml_1525a6aa7633563e0d590fe86701d51d/lib/python3.7/site-packages/matplotlib/pyplot.py", line 221, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "/home/azureuser/.azureml/envs/azureml_1525a6aa7633563e0d590fe86701d51d/lib/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'ipykernel'

[2021-04-15T22:52:42.232402] Finished context manager injector with Exception.

I have tried to import ipykernal as both a conda and pip package when creating the environment, but neither method is able to find the ipykernal package when I try to run the environment creation code. I have even tried to include the exact same version of every package that I have downloaded on my local machine (where the code runs without errors).

If anyone has any thoughts as to how to resolve this issue, I'd love to hear them. Thanks in advance for any help you can provide.

Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
3,332 questions
Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
9,013 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Gregory Jacobs 11 Reputation points
    2021-04-19T02:35:25.91+00:00

    UPDATE - I was able to resolve this issue by adding the ipykernal package as a dependency when building the python environment for my VM to run. The key was to load the ipykernel package into the environment before loading matplotlib - if I tried to load matplotlib first, it resulted in an error.

    Thanks for your help!

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.