How to Upgrade Python version on Kudu Power Shell on Azure Function Windows App

Muhammad Guruh Ajinugroho 100 Reputation points
2024-12-18T08:12:24.6933333+00:00

Hi,

I have deployed a Http Trigger Function which relies on external python script in order to perform some graphQL API calls. On my local environment I run the script with python 3.12 whereas in the Azure environment I noticed that the python version is currently 2.7.15 causing my script to have some syntax error, failing the execution.

How can I upgrade my Python executable version using the kudu power shell? As well as upgrading the pip and installing pre-requisite libraries for my function?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,331 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Deepanshu katara 12,960 Reputation points
    2024-12-18T08:32:14.8433333+00:00

    Hello , Welcome to MS Q&A

    To upgrade your Python version, pip, and install the necessary libraries using Kudu PowerShell in Azure, follow these steps:

    1. Access Kudu PowerShell:
      • Navigate to your Azure Function App in the Azure Portal.
      • Go to the "Advanced Tools" (Kudu) under the "Development Tools" section.
      • Click on "Go" to open the Kudu console.
      • In the Kudu console, click on the "Debug console" and select "PowerShell".
    2. Download and Install Python:
      • Download the desired Python version (e.g., Python 3.12) from the official Python website.
      • Use the following PowerShell commands to download and install Python
                  Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.12.0/python-3.12.0-amd64.exe" -OutFile "python-3.12.0-amd64.exe"
                  .\python-3.12.0-amd64.exe /quiet InstallAllUsers=1 PrependPath=1
                  
             
             
        
    3. Upgrade pip:
      • After installing Python, upgrade pip using the following command:
              python -m ensurepip --upgrade
              python -m pip install --upgrade pip
              
         
         
      
    4. Install Required Libraries:
      • Install the necessary libraries for your function using pip:
              python -m pip install <library_name>
              
         
         
      

    Replace <library_name> with the actual names of the libraries you need to install.

    By following these steps, you should be able to upgrade your Python version, pip, and install the required libraries for your Azure Function.

    Examples: python -m pip install numpy

    Please let us know if any questions

    Kindly accept answer if it helps

    Thanks

    Deepanshu

    0 comments No comments

  2. Pinaki Ghatak 5,565 Reputation points Microsoft Employee
    2024-12-18T12:13:22.6966667+00:00

    Hello @Muhammad Guruh Ajinugroho

    Firstly, you can try upgrading Python and pip using the Azure CLI. Here are the steps:

    1. Open the Azure CLI and navigate to your function app.
    2. Run the following command to upgrade Python to version 3.12: az webapp config set --resource-group --name --linux-fx-version "PYTHON|3.12" Replace with the appropriate values.
    3. Run the following command to upgrade pip: python3.12 -m ensurepip --default-pip This will install the latest version of pip for Python 3.12.

    If you still face access denied errors, you can try using Kudu to upgrade Python and pip. Here are the steps:

    1. Open Kudu by navigating to https://.scm.azurewebsites.net.
    2. Click on the Debug Console dropdown and select either PowerShell or CMD.
    3. Navigate to the D:\home\Python312x64 directory.
    4. Run the following command to upgrade pip: \python.exe -m ensurepip --default-pip This will install the latest version of pip for Python 3.12.
    5. Run the following command to install any required libraries: .\Scripts\pip.exe install Replace with the name of the library you want to install.

    I hope that this response has addressed your query and helped you overcome your challenges. If so, please mark this response as Answered. This will not only acknowledge our efforts, but also assist other community members who may be looking for similar solutions.

    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.