Install Python on a windows node using a start task with Azure Batch

Published 05-15-2021 11:04 PM 1,302 Views

It is common that customers contact the Azure Batch Team to provide instructions on how to install Python using the start task feature. I would like to provide the steps to perform this task in case that someone needs to work in a similar case.


Required steps:

  • Get the python release that you want to install.
  • Add the installer into a storage container.
  • Create the windows pool and define the required start task and the resource files to install the features.

Get the python release that you want to install.
 

First, download the python installer from the official site (Example below is using the 3.8.0 version for Windows) 
Download Python | Python.org

carlosbermudezlopez_0-1620665567879.png

Add the installer into a storage container.

Next step is to upload the installer to a Storage Blob Container, this installer will be downloaded to the Azure Batch Node using the Resource Files Feature in feature steps.
 

Select your Storage Account and create a new container/ select an existing one, then upload the installer.
 

carlosbermudezlopez_1-1620665586738.png

 

carlosbermudezlopez_2-1620665586745.png

Create a Windows Pool, and define the required start task and resource files.
 

Next step is to create our Windows Batch pool. We will use the required fields to create a pool, which requires to enable the Start task section.
 

carlosbermudezlopez_3-1620665635136.png

 

By using the start task run on each compute node as it joins the pool, the task will be executing when the node is added to the pool or when the node is restarted.

Once the start task configuration is enabled, we will need to define the required command line for the installation. We are using the following command line cmd /c "python-3.8.10-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0"

However, you can find all the required command lines to execute the installation in the following link.


3. Using Python on Windows — Python 3.9.5 documentation

It is important to set the User Identity to Pool Autouser, Admin to grant administrative privileges.

 

carlosbermudezlopez_4-1620665656871.png

 

Additionally, we need to define the Resource files that Azure Batch downloads to the compute node before running the command line, so once you click on the resource files option you need to click on the “pick storage blob” and it will open an interactive window where you can navigate through your storage explorer and select the installer.
 

carlosbermudezlopez_5-1620665656875.png

Important: Check the Public access level of the blob container, if you leave it as Private(no anonymous access), like in the above example, you will need to specify the “Include SaS key” when you select the resource file, otherwise you will get authentication problems. However, If the access level is set to Blob or Container it will be public.

If you are using a Private access, then it is required to mark the Include SAS and set an expiration date before adding the Resources files
 

carlosbermudezlopez_6-1620665656877.png

 

Finally, once the VM node is ready and the Start task finished, you can access the node using RDP and confirm that python is now installed.
 

carlosbermudezlopez_7-1620665656882.png

 

carlosbermudezlopez_8-1620665656893.png

You can execute the following command to confirm that the correct python version is installed.
 

carlosbermudezlopez_9-1620665656894.png

%3CLINGO-SUB%20id%3D%22lingo-sub-2341854%22%20slang%3D%22en-US%22%3EInstall%20Python%20on%20a%20windows%20node%20using%20a%20start%20task%20with%20Azure%20Batch%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2341854%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20is%20common%20that%20customers%20contact%20the%20Azure%20Batch%20Team%20to%20provide%20instructions%20on%20how%20to%20install%20Python%20using%20the%20start%20task%20feature.%20I%20would%20like%20to%20provide%20the%20steps%20to%20perform%20this%20task%20in%20case%20that%20someone%20needs%20to%20work%20in%20a%20similar%20case.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3ERequired%20steps%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EGet%20the%20python%20release%20that%20you%20want%20to%20install.%3C%2FLI%3E%0A%3CLI%3EAdd%20the%20installer%20into%20a%20storage%20container.%3C%2FLI%3E%0A%3CLI%3ECreate%20the%20windows%20pool%20and%20define%20the%20required%20start%20task%20and%20the%20resource%20files%20to%20install%20the%20features.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EGet%20the%20python%20release%20that%20you%20want%20to%20install.%3CBR%20%2F%3E%3C%2FSTRONG%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFirst%2C%20download%20the%20python%20installer%20from%20the%20official%20site%20(Example%20below%20is%20using%20the%203.8.0%20version%20for%20Windows)%26nbsp%3B%20%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fwww.python.org%2Fdownloads%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EDownload%20Python%20%7C%20Python.org%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_0-1620665567879.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279491i057134EF1FA8781E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_0-1620665567879.png%22%20alt%3D%22carlosbermudezlopez_0-1620665567879.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EA%3C%2FSTRONG%3E%3CSTRONG%3Edd%20the%20installer%20into%20a%20storage%20container.%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CBR%20%2F%3ENext%20step%20is%20to%20upload%20the%20installer%20to%20a%20%3CSTRONG%3EStorage%20Blob%20Container%3C%2FSTRONG%3E%2C%20this%20installer%20will%20be%20downloaded%20to%20the%20Azure%20Batch%20Node%20using%20the%20%3CSTRONG%3EResource%20Files%20Feature%3C%2FSTRONG%3E%20in%20feature%20steps.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESelect%20your%20%3CSTRONG%3EStorage%20Account%3C%2FSTRONG%3E%20and%20create%20a%20new%20container%2F%20select%20an%20existing%20one%2C%20then%20upload%20the%20installer.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_1-1620665586738.png%22%20style%3D%22width%3A%20669px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279494iA638DAE52C98C82A%2Fimage-dimensions%2F669x204%3Fv%3Dv2%22%20width%3D%22669%22%20height%3D%22204%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_1-1620665586738.png%22%20alt%3D%22carlosbermudezlopez_1-1620665586738.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_2-1620665586745.png%22%20style%3D%22width%3A%20704px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279495i82146655E1B58693%2Fimage-dimensions%2F704x173%3Fv%3Dv2%22%20width%3D%22704%22%20height%3D%22173%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_2-1620665586745.png%22%20alt%3D%22carlosbermudezlopez_2-1620665586745.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECreate%20a%20Windows%20Pool%2C%20and%20define%20the%20required%20start%20task%20and%20resource%20files.%3C%2FSTRONG%3E%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%20step%20is%20to%20create%20our%20%3CSTRONG%3EWindows%20Batch%20pool%3C%2FSTRONG%3E.%20We%20will%20use%20the%20required%20fields%20to%20create%20a%20pool%2C%20which%20requires%20to%20enable%20the%20Start%20task%20section.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_3-1620665635136.png%22%20style%3D%22width%3A%20550px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279496i2720E533B77B00AD%2Fimage-dimensions%2F550x389%3Fv%3Dv2%22%20width%3D%22550%22%20height%3D%22389%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_3-1620665635136.png%22%20alt%3D%22carlosbermudezlopez_3-1620665635136.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20using%20the%20start%20task%20run%20on%20each%20compute%20node%20as%20it%20joins%20the%20pool%2C%20the%20task%20will%20be%20executing%20when%20the%20node%20is%20added%20to%20the%20pool%20or%20when%20the%20node%20is%20restarted.%3CBR%20%2F%3E%3CBR%20%2F%3EOnce%20the%20start%20task%20configuration%20is%20enabled%2C%20we%20will%20need%20to%20define%20the%20required%20command%20line%20for%20the%20installation.%20We%20are%20using%20the%20following%20command%20line%20%3CSTRONG%3Ecmd%20%2Fc%20%22python-3.8.10-amd64.exe%20%2Fquiet%20InstallAllUsers%3D1%20PrependPath%3D1%20Include_test%3D0%22%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CBR%20%2F%3EHowever%2C%20you%20can%20find%20all%20the%20required%20command%20lines%20to%20execute%20the%20installation%20in%20the%20following%20link.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.python.org%2F3%2Fusing%2Fwindows.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3E3.%20Using%20Python%20on%20Windows%20%E2%80%94%20Python%203.9.5%20documentation%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3EIt%20is%20important%20to%20set%20the%20User%20Identity%20to%20%3CSTRONG%3EPool%20Autouser%2C%20Admin%3C%2FSTRONG%3E%20to%20grant%20administrative%20privileges.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_4-1620665656871.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279497i1BBBE628DC96C8B9%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_4-1620665656871.png%22%20alt%3D%22carlosbermudezlopez_4-1620665656871.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditionally%2C%20we%20need%20to%20define%20the%20%3CSTRONG%3EResource%20files%3C%2FSTRONG%3E%20that%20%3CSTRONG%3EAzure%20Batch%3C%2FSTRONG%3E%20downloads%20to%20the%20compute%20node%20before%20running%20the%20command%20line%2C%20so%20once%20you%20click%20on%20the%20resource%20files%20option%20you%20need%20to%20click%20on%20the%20%E2%80%9Cpick%20storage%20blob%E2%80%9D%20and%20it%20will%20open%20an%20interactive%20window%20where%20you%20can%20navigate%20through%20your%20storage%20explorer%20and%20select%20the%20installer.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_5-1620665656875.png%22%20style%3D%22width%3A%20679px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279498iD9B5231CB01EA2DC%2Fimage-dimensions%2F679x148%3Fv%3Dv2%22%20width%3D%22679%22%20height%3D%22148%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_5-1620665656875.png%22%20alt%3D%22carlosbermudezlopez_5-1620665656875.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImportant%3A%3C%2FSTRONG%3E%26nbsp%3BCheck%20the%20%3CSTRONG%3EPublic%20access%20level%3C%2FSTRONG%3E%20of%20the%20blob%20container%2C%20if%20you%20leave%20it%20as%20%3CSTRONG%3EPrivate(no%20anonymous%20access)%3C%2FSTRONG%3E%2C%20like%20in%20the%20above%20example%2C%20you%20will%20need%20to%20specify%20the%20%3CSTRONG%3E%E2%80%9CInclude%20SaS%20key%3C%2FSTRONG%3E%E2%80%9D%20when%20you%20select%20the%20resource%20file%2C%20otherwise%20you%20will%20get%20authentication%20problems.%20However%2C%20If%20the%20access%20level%20is%20set%20to%20%3CSTRONG%3EBlob%3C%2FSTRONG%3E%20or%20%3CSTRONG%3EContainer%3C%2FSTRONG%3E%20it%20will%20be%20public.%3CBR%20%2F%3E%3CBR%20%2F%3EIf%20you%20are%20using%20a%20%3CSTRONG%3EPrivate%20access%3C%2FSTRONG%3E%2C%20then%20it%20is%20required%20to%20mark%20the%20%3CSTRONG%3EInclude%20SAS%3C%2FSTRONG%3E%20and%20set%20an%20expiration%20date%20before%20adding%20the%20%3CSTRONG%3EResources%20files%3C%2FSTRONG%3E%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_6-1620665656877.png%22%20style%3D%22width%3A%20645px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279499i143A572DE310C5C6%2Fimage-dimensions%2F645x187%3Fv%3Dv2%22%20width%3D%22645%22%20height%3D%22187%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_6-1620665656877.png%22%20alt%3D%22carlosbermudezlopez_6-1620665656877.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFinally%2C%20once%20the%20VM%20node%20is%20ready%20and%20the%3CSTRONG%3E%20Start%20task%3C%2FSTRONG%3E%20finished%2C%20you%20can%20access%20the%20node%20using%20RDP%20and%20confirm%20that%20python%20is%20now%20installed.%20%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_7-1620665656882.png%22%20style%3D%22width%3A%20598px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279501iF2612EA425660F12%2Fimage-dimensions%2F598x196%3Fv%3Dv2%22%20width%3D%22598%22%20height%3D%22196%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_7-1620665656882.png%22%20alt%3D%22carlosbermudezlopez_7-1620665656882.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_8-1620665656893.png%22%20style%3D%22width%3A%20622px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279502i749A573C8A4AD9EF%2Fimage-dimensions%2F622x251%3Fv%3Dv2%22%20width%3D%22622%22%20height%3D%22251%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_8-1620665656893.png%22%20alt%3D%22carlosbermudezlopez_8-1620665656893.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EYou%20can%20execute%20the%20following%20command%20to%20confirm%20that%20the%20correct%20python%20version%20is%20installed.%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22carlosbermudezlopez_9-1620665656894.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279500i43794EFBED356005%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22carlosbermudezlopez_9-1620665656894.png%22%20alt%3D%22carlosbermudezlopez_9-1620665656894.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2341854%22%20slang%3D%22en-US%22%3E%3CP%3EIt%20is%20common%20that%20customers%20contact%20the%20Azure%20Batch%20Team%20to%20provide%20instructions%20on%20how%20to%20install%20Python%20using%20the%20start%20task%20feature.%20I%20would%20like%20to%20provide%20the%20steps%20to%20perform%20this%20task%20in%20case%20that%20someone%20needs%20to%20work%20in%20a%20similar%20case.%3C%2FP%3E%0A%3CP%3E%3CBR%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Batch.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F279503i9780CE08E2110F92%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Batch.png%22%20alt%3D%22Batch.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2341854%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20Batch%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎May 11 2021 05:50 PM
Updated by: