![](/img/trans.png)
[英]ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob'
[英]Cannot import name BlockBlobService from azure.storage.blob
雖然,我問的問題有很多類似的問題,但沒有一個對我有幫助。
我正在嘗試使用 python 腳本直接通過我的系統將文件存儲到我的 azure 存儲 blob 中。
這是我正在使用的腳本:
import os, uuid, sys
from azure.storage.blob import BlockBlobService, PublicAccess
def run_sample():
try:
block_blob_service = BlockBlobService(account_name=<acc-name>, account_key=<acc-key>)
# Create a file in Documents to test the upload and download.
local_path=os.path.abspath(os.path.curdir)
local_file_name =input("Enter file name to upload : ")
full_path_to_file =os.path.join(local_path, local_file_name)
print("Temp file = " + full_path_to_file)
print("\nUploading to Blob storage as blob" + local_file_name)
# Upload the created file, use local_file_name for the blob name
container_name ='handwritten-text'
block_blob_service.create_blob_from_path(container_name, local_file_name, full_path_to_file)
# List the blobs in the container
print("\nList blobs in the container")
generator = block_blob_service.list_blobs(container_name)
for blob in generator:
print("\t Blob name: " + blob.name)
except Exception as e:
print(e)
# Main method.
if __name__ == '__main__':
run_sample()
雖然,如果我正在運行腳本,我會收到以下錯誤:
ImportError: cannot import name 'BlockBlobService' from 'azure.storage.blob' (/home/nishant/anaconda3/envs/mera_env/lib/python3.7/site-packages/azure/storage/blob/__init__.py)
這是pip freeze的結果:
azure-cognitiveservices-vision-computervision==0.6.0
azure-common==1.1.25
azure-core==1.8.0
azure-storage-blob==12.3.2
我該如何解決這個問題?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.