简体   繁体   English

尝试使用 Python 库 azure-storage-blob 时未解决的导入“azure.storage.blob”

[英]Unresolved import 'azure.storage.blob' when trying to use Python library azure-storage-blob

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

I'm trying to use Python library, azure-storage-blob to extract the file names of the files stored in blob.我正在尝试使用 Python 库 azure-storage-blob 来提取存储在 blob 中的文件的文件名。 I already installed all required package as followed using conda as I am using virtual environment in anaconda.我已经使用 conda 安装了所有必需的软件包,因为我在 anaconda 中使用虚拟环境。

conda install -c anaconda azure conda install -c conda-forge azure-storage-blob conda install -c conda-forge azure-nspkg conda install -c anaconda azure conda install -c conda-forge azure-storage-blob conda install -c conda-forge azure-nspkg

But my code won't compile with error message Unresolved import 'azure.storage.blob' I also have an error: ModuleNotFoundError: No module named 'azure'但是我的代码无法编译并显示错误消息 Unresolved import 'azure.storage.blob' 我也有一个错误: ModuleNotFoundError: No module named 'azure'

But, I already installed these packages.但是,我已经安装了这些软件包。 Could you please let me know how I can resolve this issue?你能告诉我如何解决这个问题吗?

Here is my code:这是我的代码:

    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)

未解决

未找到模块

I found out that with visual studio code, this is not really an error.我发现使用 Visual Studio 代码,这并不是一个真正的错误。 As, when I tried to run with command python <script.py>, my script actually executed.因为,当我尝试使用命令 python <script.py> 运行时,我的脚本实际执行了。 Therefore, installing these packages are enough to use these libraries: conda install -c anaconda azure conda install -c conda-forge azure-storage-blob因此,安装这些包就足以使用这些库: conda install -c anaconda azure conda install -c conda-forge azure-storage-blob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为 python 安装 azure.storage.blob 库? - How to install azure.storage.blob library for python? 无法从 Azure 函数中的 azure.storage.blob 导入 AppendBlobService - Unable to import AppendBlobService from azure.storage.blob in Azure function ImportError:无法从“azure.storage.blob”导入名称“BlockBlobService” - ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob' Docker:无法从“azure.storage.blob”导入名称“BlobServiceClient” - Docker: cannot import name 'BlobServiceClient' from 'azure.storage.blob 无法从 azure.storage.blob 导入名称 BlockBlobService - Cannot import name BlockBlobService from azure.storage.blob ImportError:没有名为azure.storage.blob的模块 - ImportError: No module named azure.storage.blob 导入azure.storage.blob时出现xml.etree错误 - xml.etree error when importing azure.storage.blob 使用 Azure-Storage-Blob Python 读取 Blob 容器目录中每个 Blob 的文件大小 - Reading the File size for each blob inside a directory of a Blob Container using Azure-Storage-Blob Python Using azure.storage.blob to write Python DataFrame as CSV into Azure Blob - Using azure.storage.blob to write Python DataFrame as CSV into Azure Blob 出现ImportError:执行python manage.py syncdb时没有名为azure.storage.blob的模块 - Getting ImportError: No module named azure.storage.blob when doing python manage.py syncdb
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM