gpt4 book ai didi

python - 尝试使用 Python 库 azure-storage-blob 时出现未解析的导入 'azure.storage.blob'

转载 作者:行者123 更新时间:2023-12-03 00:01:42 25 4
gpt4 key购买 nike

以下 URL 为例:https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-python#list-the-blobs-in-a-container

我正在尝试使用Python库azure-storage-blob来提取存储在blob中的文件的文件名。我已经使用 conda 安装了所有必需的软件包,因为我在 anaconda 中使用虚拟环境。

conda安装-c anaconda azureconda 安装-c conda-forge azure-storage-blobconda install -c conda-forge azure-nspkg

但是我的代码无法编译,并显示错误消息 Unresolved import 'azure.storage.blob'我也有一个错误:ModuleNotFoundError:没有名为“azure”的模块

但是,我已经安装了这些软件包。您能否告诉我如何解决这个问题?

这是我的代码:

    import os, uuid
from azure.storage.blob import BlobClient, BlobServiceClient, ContainerClient, __version__

try:
print("Azure Blob Storage v" + __version__ + " - Python sample")
except Exception as ex:
print('Exception:')
print(ex)

# Retrieve the connection string for use with the application. The storage
# connection string is stored in an environment variable on the machine
# running the application called AZURE_STORAGE_CONNECTION_STRING. If the environment variable is
# created after the application is launched in a console or with Visual Studio,
# the shell or application needs to be closed and reloaded to take the
# environment variable into account.
connect_str = os.getenv('AZURE_STORAGE_CONNECTION_STRING')

# Create BlobServiceClient object
blob_service_client = BlobServiceClient.from_connection_string(connect_str)

containers_list = blob_service_client.list_containers

print(containers_list)

unresolved

modulenotfound

最佳答案

我发现使用 Visual Studio 代码,这并不是一个真正的错误。因为,当我尝试使用命令 python <script.py> 运行时,我的脚本实际上被执行了。因此,安装这些包就足以使用这些库:conda 安装-c anaconda azureconda install -c conda-forge azure-storage-blob

关于python - 尝试使用 Python 库 azure-storage-blob 时出现未解析的导入 'azure.storage.blob',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64141052/

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