gpt4 book ai didi

python-3.x - Azure Python 函数中导入模块错误 (Linux)

转载 作者:行者123 更新时间:2023-12-03 04:02:19 24 4
gpt4 key购买 nike

我已使用 VS Code 在 Windows 计算机中创建了 Python 队列触发器。为了安装模块,我创建了虚拟环境并 pip 安装了所有必需的模块。我在消费计划中将此 functionApp 从 VSCode 部署到 Linux 操作系统上的 Azure。当我从 Azure 运行此函数时,它会抛出导入模块错误,如果它没有获取模块,我就不会抛出导入模块错误。没有可用于安装模块的 Kudu。我已将所有模块版本放在 Requirement.txt 中。需求.txt-

azure-common==1.1.25
azure-core==1.4.0
azure-functions==1.2.0
azure-nspkg==3.0.2
azure-storage==0.36.0
azure-storage-blob==12.3.0
azure-storage-common==2.1.0
certifi==2020.4.5.1
cffi==1.14.0
chardet==3.0.4
cryptography==2.9.2
idna==2.9
isodate==0.6.0
msrest==0.6.13
numpy==1.18.3
oauthlib==3.1.0
pandas==1.0.3
pip==19.2.3
pycparser==2.20
python-dateutil==2.8.1
pytz==2020.1
requests==2.23.0
requests-oauthlib==1.3.0
setuptools==41.2.0
six==1.14.0
urllib3==1.25.9
wheel==0.34.2

我的虚拟环境文件夹与所有函数处于同一级别,并且我使用的是 python 3.6。代码截图-

import os

import platform
import json
import requests
import datetime
import pandas as pd
import numpy as np
from datetime import timedelta
from pandas import json_normalize
from azure.storage.blob import BlockBlobService, AppendBlobService
import azure.functions as func


# read the queue message and write to stdout
def main(msg: func.QueueMessage):
print ("ShiftAdmitPreprocessingWest - started")
blobaccess = msg.get_json()

来自 Azure 的错误 -

Result: Failure
Exception: ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob' (/home/site/wwwroot/.python_packages/lib/site-packages/azure/storage/blob/__init__.py)
Stack: File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 242, in _handle__function_load_request
func_request.metadata.entry_point)
File "/azure-functions-host/workers/python/3.7/LINUX/X64/azure_functions_worker/loader.py", line 66, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/ShiftAdmitPreprocessingWest/__init__.py", line 14, in <module>
from azure.storage.blob import BlockBlobService, AppendBlobService

最佳答案

你可以试试这个方法吗?

from azure.storage.blob.blockblobservice import BlockBlobService

Related Issue

关于python-3.x - Azure Python 函数中导入模块错误 (Linux),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61618597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com