Search code examples
pythonvscode-extensionsazure-automationazure-runbook

VS Code Azure Automation Runbook Python Packages not recognized


I am unable to view my python packages through visual studio code. Verified on Azure portal that all the necessary packages are uploaded. I use python 3.8.10 on my local machine as the interpreter as these packages were verified with 3.8 runtime. I use the following link as a guide : (https://learn.microsoft.com/en-us/azure/automation/how-to/runbook-authoring-extension-for-vscode). quoted from the link under perquisites 'PowerShell modules and Python packages used by runbook must be locally installed on the machine to run the runbook locally.' I do have it locally stored as whl file, but do I have to configure the scripts to point it to the directory? my objective of using VS code is so that I can run the code locally quickly and do debugging instead of running it via the azure portal, which takes very long time.

Is it necessary to create virtual environment for my case?

Python Packages not recognized

Python Packages uploaded to Azure Portal

Error Message in VS Code

Running runbook locally error

VS Code Terminal Directory

Have tried making sure the Python interpreter is selected.

read the following links under limitations: Link


Solution

  • Firstly, yes you need to add the Python Packages resource of the Automation Account to run the runbook locally and it is also mentioned here in the MSDoc.

    In my VSCode environment, I tried to execute below sample code and received the same error as you.

    from azure.mgmt.resource import ResourceManagementClient
    print ("Hello")
    

    Then I used pip install azure-mgmt-resource command in the terminal to install the specific package.

    enter image description here

    Note: To install whl files, you can also use pip install <packagename>.whl in the specific directory where the runbook is located of VSCode terminal.

    Once you have installed the packages, check with below command whether it is installed accurately.

    pip list

    enter image description here

    To work with Python runbooks locally, always use virtual environment as it avoids conflicts.

    py -m venv .venv
    .venv\Scripts\activate
    

    Also restart the VSCode once everything has installed if still the issue persists.