Genesis-5244 avatar image
1 Vote"
Genesis-5244 asked ChaitanyaNaykodiMSFT-9638 commented

Pandas import causing problems with Azure Function

I am trying to put together an Azure function to run on an HTTP trigger. My problem is whenever I run the function I get a key error exception from the six module. It seems to be called when importing pandas and I cannot figure out why. Here is the traceback:

 Exception has occurred: KeyError
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/", line 198, in load_module
     return sys.modules[fullname]
   File "/Users/benjaminhack/Desktop/GenesisAnalytics/Sentiment Analysis/Pipleines/functions/HttpTrigger1/", line 2, in <module>
     import pandas as pd
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/", line 76, in load_function
     mod = importlib.import_module(fullmodname)
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/utils/", line 32, in call
     return func(*args, **kwargs)
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/", line 275, in _handle__function_load_request
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/", line 242, in _dispatch_grpc_request
     resp = await request_handler(request)
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/", line 48, in main, args.port, args.worker_id, args.request_id))
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/", line 86, in <module>

The code is supposed to run a function on an HTTP trigger where the function uses pandas.The following code snippet from the function's has the import statement where the error occurs:

 import logging
 import pandas as pd
 import azure.functions as func
 from .scraper import total_scrape
 from .cleaning_analysis import clean_tweets, run_sentiment_analysis
 def main(req: func.HttpRequest) -> func.HttpResponse:'Python HTTP trigger function processed a request.')
     ### SCRAPE ###"Initiating scrape")
     df = total_scrape()"Scraping complete")"Shape: {}".format(df.shape))
     ### CLEAN ###
     df = clean_tweets(df)
"Cleaning complete")
     ### ANALYSIS ###
     df = run_sentiment_analysis(df)"Sentiment Analysis completed")
     return func.HttpResponse(f"{}")

Any help would be greatly appreciated. Thank you!

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @Genesis-5244, Thank you for reaching out. Can you please follow the mitigation steps mentioned here in the this troubleshooting document to see if you need to update your packages or check for compatibility issues. If this does not help resolve the issue can you please follow the steps mentioned here and provide a screenshot of the requirements.txt file?
Please let me know if there are any concerns. Thank you!

1 Vote 1 ·
Genesis-5244 avatar image Genesis-5244 ChaitanyaNaykodiMSFT-9638 ·

Thank you very much, I will try it out now. Here is the requirements.txt file:

 # DO NOT include azure-functions-worker in this file
 # The Python Worker is managed by Azure Functions platform
 # Manually managing azure-functions-worker may cause unexpected issues

0 Votes 0 ·

1 Answer

ChaitanyaNaykodiMSFT-9638 avatar image
0 Votes"
ChaitanyaNaykodiMSFT-9638 answered ChaitanyaNaykodiMSFT-9638 commented

Hello @Genesis-5244, Thank you for the information provided above, but I could not replicate the issue on my end. I think the issue is related to local environment set-up, to test this can you please deploy your function app to Azure and see if you receive the same error.
Additionally on your local machine can you try the steps mentioned below.
1. Can you please check if the correct Python interpreter is selected by following the steps mentioned here
2. Open a new terminal in VS Code. You should see the (.venv) and run the pip list command as shown below and see if you have all the packages installed listed in your requirements.txt. If not you can install them by running the command pip install -r requirements.txt


  1. Then you can run the func host start command and see if the issue still persists.


I have followed the steps mentioned here to create the function app. Please let me know if the issue still persists. Thank you!

image.png (152.8 KiB)
image.png (151.2 KiB)
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you very much for this! Deployment to the cloud failed with the error:
Error: Deployment '531f2bb7b2b84fd7a696d829b224c0d3' not found.

I will try the rest of the steps and get back to you on my progress.

0 Votes 0 ·

The function app is working. Thank you for all the assistance.

0 Votes 0 ·

Hello @Genesis-5244, Thank you for letting me know, I am glad the issue is resolved. Thank you!

0 Votes 0 ·