Skip to content

Commit e7c5d5a

Browse files
author
Simonx Xu
authored
Merge pull request #9169 from AmandaAZ/Branch-CI6187
AB#6187: Error running a Python runbook
2 parents 905d50f + 6e41cc7 commit e7c5d5a

File tree

2 files changed

+129
-0
lines changed

2 files changed

+129
-0
lines changed
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
---
2+
title: Troubleshoot Issues with Python Packages in Azure Automation
3+
description: Describes how to import, manage, and use Python packages in Azure Automation and provides a solution to an issue with python packages.
4+
ms.date: 06/27/2025
5+
ms.reviewer: adoyle, v-weizhu
6+
ms.service: azure-automation
7+
ms.custom: sap:Runbook not working as expected
8+
---
9+
# Troubleshoot issues with python packages in Azure Automation
10+
11+
The article shows how to import, manage, and use Python packages in Azure Automation running on the Azure sandbox environment and Hybrid Runbook Workers. Python packages should be downloaded on Hybrid Runbook workers for successful job execution. To help simplify runbooks, you can use Python packages to import the modules you need.
12+
13+
> [!NOTE]
14+
> Azure Automation enables the recovery of runbooks deleted in the last 29 days. You can restore the deleted runbook by running a PowerShell script as a job in your Automation account. For more information, see [Restore deleted runbook](/azure/automation/manage-runbooks#restore-deleted-runbook).
15+
16+
## Import Python 2 packages
17+
18+
1. In your Automation account, select **Python packages** under **Shared Resources**. Select **+ Add a Python package**.
19+
20+
2. On the **Add Python Package** page, select a local package to upload. The package can be a **.whl** or **.tar.gz** file.
21+
22+
3. Enter the name and select the **Runtime version** as "2.x.x".
23+
24+
4. Select **Import**.
25+
26+
After a package is imported, it's listed on the **Python packages** page in your Automation account. To remove a package, select the package and select **Delete**.
27+
28+
## Import packages with dependencies
29+
30+
Azure Automation doesn't resolve dependencies for Python packages during the import process. Use one of the following methods to import a package with all its dependencies.
31+
32+
### Method 1: Manually download
33+
34+
On a Windows 64-bit machine with Python 2.7 and the [package installer for Python (pip)](https://pip.pypa.io/en/stable/), download a package and all its dependencies by running the following command:
35+
36+
```console
37+
C:\Python27\Scripts\pip2.7.exe download -d <output-directory> <package-name>
38+
```
39+
40+
Once the packages and all its dependencies are downloaded, you can import them into your Automation account.
41+
42+
### Method 2: Use a runbook
43+
44+
To get a runbook, [import Python 2 packages from pypi into Azure Automation account](https://github.com/azureautomation/import-python-2-packages-from-pypi-into-azure-automation-account).
45+
46+
When you start the runbook, ensure the following things:
47+
48+
- The **Run on** option under **Run Settings** is set to **Azure**.
49+
- The runbook is started with the following parameters and each parameter is defined with a `switch`.
50+
51+
- -s \<subscriptionId\>
52+
- -g \<resourceGroup\>
53+
- -a \<automationAccount\>
54+
- -m \<modulePackage\>
55+
56+
The runbook allows you to specify which package to download. For example, set the `-m` parameter to `Azure` to download all Azure modules and all dependencies (approximately 105 packages).
57+
- The runbook requires a managed identity for the Automation account to work.
58+
59+
After the runbook execution is complete, you can check the **Python packages** under **Shared Resources** in your Automation account to verify that the package is imported correctly.
60+
61+
## Default Python 3 packages
62+
63+
To support Python 3.8 runbooks in the Automation service, some Python packages are installed by default. For more information, see [Default Python packages](/azure/automation/default-python-packages). The default version can be overridden by importing Python packages into your Automation account. The imported version is preferred in your Automation account. To import a single package, see [Import a Python 3 package](#import-a-python-3-package). To import a package with multiple packages, see [Import a Python 3 package with dependencies](#import-a-python-3-package-with-dependencies).
64+
65+
> [!NOTE]
66+
> Python 3.10 (preview) doesn't have default packages installed.
67+
68+
## Import a Python 3 package
69+
70+
1. In your Automation account, select **Python packages** under **Shared Resources**. Then, select **+ Add a Python package**.
71+
72+
2. On the **Add Python Package** page, select a local package to upload. The package can be a **.whl** or **.tar.gz** file for Python 3.8 and a **.whl** file for Python 3.10 (preview).
73+
74+
3. Type a name and select the **Runtime Version** as Python 3.8 or Python 3.10 (preview).
75+
76+
4. Select **Import**.
77+
78+
After a package is imported, it's listed on the Python packages page in your Automation account. To remove a package, select the package and select **Delete**.
79+
80+
## Import a Python 3 package with dependencies
81+
82+
You can import a Python 3.8 package and its dependencies by importing the Python script [import_py3package_from_pypi.py](https://github.com/azureautomation/runbooks/blob/master/Utility/Python/import_py3package_from_pypi.py) into a Python 3.8 runbook. Ensure that a managed identity is enabled for your Automation account and has Automation Contributor access to import the package successfully.
83+
84+
### Import the script into a runbook
85+
86+
For more information about importing the runbook, see [Import a runbook from the Azure portal](/azure/automation/manage-runbooks#import-a-runbook-from-the-azure-portal). Copy the file from GitHub to storage that the Azure portal can access before you run the import.
87+
88+
The **Import a runbook** page defaults the runbook name to match the name of the script. If you have access to the field, you can change the name. **Runbook type** might default to **Python 2.7**. If it does, make sure to change it to **Python 3.8**.
89+
90+
### Execute the runbook to import the package and dependencies
91+
92+
After creating and publishing the runbook, run it to import the package. For more information about executing a runbook, see [Start a runbook in Azure Automation](/azure/automation/start-runbooks).
93+
94+
The script (import_py3package_from_pypi.py) requires the following parameters.
95+
96+
|Parameter|Description|
97+
|----|----|
98+
|`subscription_id`|Subscription ID of the Automation account|
99+
|`resource_group`|Name of the resource group where the Automation account is defined|
100+
|`automation_account`|Automation account name|
101+
|`module_name`|Name of the module to import from *pypi.org*|
102+
|`module_version`|Version of the module|
103+
104+
Parameter value should be provided as a single string in the following format:
105+
106+
`-s <subscription_id> -g <resource_group> -a<automation_account> -m <module_name> -v <module_version>`
107+
108+
## Scenario: Runbook fails with "Parameter length exceeded" error
109+
110+
Your runbook that uses those parameters fails with the following error:
111+
112+
> Total Length of Runbook Parameter names and values exceeds the limit of 30,000 characters. To avoid this issue, use Automation Variables to pass values to runbook.
113+
114+
### Cause
115+
116+
Python 2.7, Python 3.8, and PowerShell 7.1 runbooks have a limit on the total length of characters for all parameters provided. The total length of all parameter names and values can't exceed 30,000 characters.
117+
118+
### Resolution
119+
120+
To resolve this issue, use Azure Automation Variables to pass values to the runbook or shorten parameter names and values so they don't exceed 30,000 characters in total.
121+
122+
## References
123+
124+
- [Manage modules in Azure Automation](/azure/automation/shared-resources/modules)
125+
- [Runbook execution in Azure Automation](/azure/automation/automation-runbook-execution)
126+
- [Manage Python 2 packages in Azure Automation](/azure/automation/python-packages)
127+
- [Manage Python 3 packages in Azure Automation](/azure/automation/python-3-packages)

support/azure/automation/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
items:
55
- name: Runbook jobs get suspended
66
href: runbooks/runbook-job-suspended.md
7+
- name: Troubleshoot issues with python packages
8+
href: runbooks/error-running-python-runbook.md
79
- name: Troubleshoot runbook execution issues when using PowerShell
810
href: runbooks/powershell-job-script-cmdlets-not-working.md
911

0 commit comments

Comments
 (0)