【问题标题】:Key error in six.moves with return sys.modules[fullname]6.moves 中的关键错误,返回 sys.modules[fullname]
【发布时间】:2021-04-01 09:37:33
【问题描述】:

我正在尝试组合一个 Azure 函数以在 HTTP 触发器上运行。我的问题是每当我运行该函数时,我都会从六个模块中得到一个关键错误异常。导入熊猫时似乎调用了它,我不知道为什么。这是回溯:

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

该代码应该在函数使用 pandas 的 HTTP 触发器上运行函数。来自函数__init__.py 的以下代码 sn-p 具有发生错误的导入语句:

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

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

【问题讨论】:

  • 能否提供您的功能项目结构?

标签: python pandas azure azure-functions six


【解决方案1】:

原来我的问题是由于本地环境配置不当引起的。重做虚拟环境后,它自己整理得很好。

【讨论】:

  • 您能否提供更多有关“配置错误”本地环境的信息。我刚刚删除了我的本地环境并重新创建,但仍然得到了 Six.moves 的 KeyError。我的 requirements.txt 中也没有引用六个。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多