Pandas import causing problems with Azure Function

Genesis 76 Reputation points
2021-03-30T12:27:41.187+00:00

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
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,249 questions
{count} votes

Accepted answer
  1. ChaitanyaNaykodi-MSFT 22,701 Reputation points Microsoft Employee
    2021-04-01T23:01:22.813+00:00

    Hello @Genesis , 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!


0 additional answers

Sort by: Most helpful