skip to Main Content

I’m trying to run my azure functions locally (using Postman) for testing. To do this I am accessing via command line (cmd) and run "func start".
Once I run this function in my azure function folder, the command line gives me a huge error that I can’t paste into this question because it’s so big, but I know it’s attributed to Python modules .
After that error, the cmd still gives me a list of azure functions. To better understand my problem, I leave here a set of images.

enter image description here

enter image description here

enter image description here

enter image description here

I have already reviewed the requirement.txt and there are all the libraries that should be installed. I also checked that these libraries were installed on my PC and in the .venv that is created for the azure functions.

Here I leave a copy of my requirement.txt (I must also mention that I already uninstalled and installed the requirements)

azure-functions == 1.13.3
chardet == 5.1.0
azure-storage-blob == 12.15.0
pandas == 1.5.3
pyodbc == 4.0.34
SQLAlchemy == 1.4.39
statsmodels == 0.13.2
datetime == 5.1
numpy == 1.21.5
adal == 1.2.7
requests == 2.28.1
cchardet == 2.1.7
Office365-REST-Python-Client == 2.3.16
openpyxl == 3.0.10

I hope someone can give me a clue as to what mistake I may be making.
Greetings and thanks!

2

Answers


  1. In my experience, this error usually show up when the python version defined in the functionapp isn’t the same as the version you’re running locally.

    Make sure that the versions, locally (3.9) and the functionapp, are the same.

    Login or Signup to reply.
  2. I tried running the below Azure function and got results as below:-

    My requirements.txt

    azure-functions
    pandas
    pyodbc
    

    My init.py

    import  logging
    
    import  azure.functions  as  func
    
    import pyodbc
    
    import  pandas  as  pd
    
     
    def  main(req: func.HttpRequest) -> func.HttpResponse:
    
    logging.info('Python HTTP trigger function processed a request.')
    
    
    # Define connection string and query
    
    connection_string = "Driver={ODBC Driver 17 for SQL Server};Server=siliconserver654.database.windows.net;Database=silicondb987;Uid=siliconuser;Pwd=Watermelon@123;"
    
    query = "SELECT * FROM <table_name>"
    
      
    
    # Create connection and retrieve data using pandas
    
    with  pyodbc.connect(connection_string) as  conn:
    
    df = pd.read_sql(query, conn)
    
      
    
    # Return the first 10 rows of data as a JSON response
    
    return  func.HttpResponse(df.head(10).to_json(), mimetype="application/json")
    

    When I ran my function app by Pressing F5 key or fn + F5 key or func host start .
    The Function app ran like below, installed the packages and triggered HTTP Request.

    func host start
    

    enter image description here

    enter image description here

    Browser:-

    enter image description here

    If the above method does not work, Try to install your packages by using pip install in your terminal and then run the Function app again:-

    Code:-

    pip install pyodbc
    
    pip install pandas
    
     pip install -r requirements.txt
    

    Output:-

    enter image description here
    In your virtual environment (venv) check if the packages are installed like below:-

    enter image description here

    I tried running the Function app in Python Version 3.11 as well as 3.10 and it triggered successfully.

    Reference:-

    Pandas import causing problems with Azure Function – Microsoft Q&A

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search