ModuleNotFoundError: No module named 'azureml' in ML Studio

Shan Jaffry 1 Reputation point
2022-01-25T19:52:31.313+00:00

I am learning Azure ML from Microsoft tutorials, here. The third tutorial is giving me the following error.

[stderr]Traceback (most recent call last):  
[stderr]  File "train.py", line 8, in <module>  
[stderr]    from azureml.core import Run  
[stderr]ModuleNotFoundError: No module named 'azureml'  
[stderr]  

Working with Azure ML Studio and submitting the code to the environment, I am unable to find how to resolve this error.

I have checked that the package is installed (running on Azure ML studio so this is a basic assumption, but I have tested as well). Following is the code 'run-pytorch.py' which calls the script 'train.py'

# run-pytorch.py  
from azureml.core import Workspace  
from azureml.core import Experiment  
from azureml.core import Environment  
from azureml.core import ScriptRunConfig  
  
if __name__ == "__main__":  
    ws = Workspace.from_config()  
    experiment = Experiment(workspace=ws, name='day1-experiment-train')  
    config = ScriptRunConfig(source_directory='./src',  
                             script='train.py',  
                             compute_target='cpu-cluster')  
  
    # set up pytorch environment  
    env = Environment.from_conda_specification(  
        name='pytorch-env',  
        file_path='pytorch-env.yml'  
    )  
    config.run_config.environment = env  
  
    run = experiment.submit(config)  
  
    aml_url = run.get_portal_url()  
    print(aml_url)  
    print('Success...!!!')  

The code snippet for train.py is as follows

# train.py  
import os  
import argparse  
import torch  
import torch.optim as optim  
import torchvision  
import torchvision.transforms as transforms  
from model import Net  
from azureml.core import Run  
...  
...  
Azure Machine Learning
Azure Machine Learning
An Azure machine learning service for building and deploying models.
2,741 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. YutongTie-MSFT 48,821 Reputation points
    2022-01-26T01:08:44.91+00:00

    @Shan Jaffry

    Sorry for your experience and thanks for reaching out to us, I am able to reproduce your issue with my new create compute-cpu, the resolution is easy to install the azureml in your compute at the terminal under your root user.

    pip install azureml  
    

    168525-image.png

    Just in case, I encounter pyarrow error after that, the resolution is uninstall the pyarrow 4.0 and install pyarrow 3.0.0 instead as below:

    pip uninstall pyarrow  
          
    pip install pyarrow==3.0.0  
    

    I have forwarded this bug to product group and hope to make this process smoother.

    Please kindly accept the answer if you feel this is helpful. Thank you.

    Regards,
    Yutong

    1 person found this answer helpful.
    0 comments No comments

  2. Shan Jaffry 1 Reputation point
    2022-01-26T06:17:11.51+00:00

    Thanks for your answer.

    I tried what you mentioned, but it does not work, unfortunately. Same error.
    First of all, it says that the 'Requirement already satisfied'.

    snapshot of installation

    Secondly, I can see that azureml is already installed. Furthermore, as I mentioned earlier, that it is running in other cases. Not running for this particular case ! I appreciate your help.

    168592-image.png

    168614-image.png