question

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
 'six.moves'
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/six.py", line 198, in load_module
     return sys.modules[fullname]
   File "/Users/benjaminhack/Desktop/GenesisAnalytics/Sentiment Analysis/Pipleines/functions/HttpTrigger1/__init__.py", 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/loader.py", 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/wrappers.py", 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/dispatcher.py", line 275, in _handle__function_load_request
     func_request.metadata.entry_point)
   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.3388/workers/python/3.7/OSX/X64/azure_functions_worker/dispatcher.py", 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/main.py", line 48, in main
     args.host, 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/worker.py", line 86, in <module>
     main.main()


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 __init__.py 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:
     logging.info('Python HTTP trigger function processed a request.')
    
     ### SCRAPE ###
     logging.info("Initiating scrape")
     df = total_scrape()
     logging.info("Scraping complete")
     logging.info("Shape: {}".format(df.shape))
    
     ### CLEAN ###
        
     df = clean_tweets(df)
    
     logging.info("Cleaning complete")
    
     ### ANALYSIS ###
     df = run_sentiment_analysis(df)
     logging.info("Sentiment Analysis completed")
        
     return func.HttpResponse(f"{df.info}")


Any help would be greatly appreciated. Thank you!


azure-functions
· 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
    
 azure-functions
 datetime
 joblib
 matplotlib
 nest-asyncio
 nltk
 numpy
 pandas
 regex
 six
 sklearn
 textblob
 twint


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


83759-image.png

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

83760-image.png

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 ·