返回系统模块[fullname]时在six.moves中出现键错误

2024-03-29 12:30:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试组合一个Azure函数以在HTTP触发器上运行。我的问题是,每当我运行该函数时,我都会从six模块得到一个键错误异常。在进口大熊猫时,它似乎被称为熊猫,我不知道为什么。以下是回溯:

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()

该代码应在HTTP触发器上运行函数,该函数使用pandas。函数的__init__.py中的以下代码段包含发生错误的import语句:

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}")

任何帮助都将不胜感激。谢谢大家!


Tags: inpycoreimportusrlocallinefunctions