Reputation: 319
Following this URL as example: https://learn.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. I already installed all required package as followed using conda as I am using virtual environment in anaconda.
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'
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)
Upvotes: 4
Views: 4813
Reputation: 319
I found out that with visual studio code, this is not really an error. As, when I tried to run with command python <script.py>, my script actually executed. Therefore, installing these packages are enough to use these libraries: conda install -c anaconda azure conda install -c conda-forge azure-storage-blob
Upvotes: 1