[英]Unresolved import 'azure.storage.blob' when trying to use Python library azure-storage-blob
以下 URL 为例: https : //docs.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 install -c anaconda azure conda install -c conda-forge azure-storage-blob conda install -c conda-forge azure-nspkg
但是我的代码无法编译并显示错误消息 Unresolved import 'azure.storage.blob' 我也有一个错误: ModuleNotFoundError: No module named '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)
我发现使用 Visual Studio 代码,这并不是一个真正的错误。 因为,当我尝试使用命令 python <script.py> 运行时,我的脚本实际执行了。 因此,安装这些包就足以使用这些库: conda install -c anaconda azure conda install -c conda-forge azure-storage-blob
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.