本文介绍了ImportError:使用Azure后端时无法导入名称"BlobService"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按照以下说明将Azure设置为我的后端服务: http://django-storages.readthedocs.io/en/latest/backends/azure.html

I followed these instructions to set up Azure as my backend service:http://django-storages.readthedocs.io/en/latest/backends/azure.html

还在此文档中添加了其他软件包: https://docs .microsoft.com/zh-CN/azure/storage/blobs/storage-python-how-to-use-blob-storage

Also added additional packages per this document:https://docs.microsoft.com/en-us/azure/storage/blobs/storage-python-how-to-use-blob-storage

出现此错误:追溯(最近一次通话):

Getting this error:Traceback (most recent call last):

  File "/usr/local/lib/python3.6/site-packages/storages/backends/azure_storage.py", line 23, in <module>
    from azure.storage.blob.blobservice import BlobService
ModuleNotFoundError: No module named 'azure.storage.blob.blobservice'

....

  File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 978, in _gcd_import
  File "<frozen importlib._bootstrap>", line 961, in _find_and_load
  File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
  File "/usr/local/lib/python3.6/site-packages/storages/backends/azure_storage.py", line 26, in <module>
    from azure.storage import BlobService
ImportError: cannot import name 'BlobService'
[12/Oct/2017 01:38:00] "POST /upload HTTP/1.1" 500 18034

我的pip3冻结看起来像这样:

My pip3 freeze looks like so:

(venv) Mikes-MacBook:drhazelapp mikebz$ pip3 freeze | grep azure
azure==2.0.0
azure-batch==3.0.0
azure-common==1.1.8
azure-datalake-store==0.0.17
azure-graphrbac==0.30.0
azure-keyvault==0.3.7
azure-mgmt==1.0.0
azure-mgmt-authorization==0.30.0
azure-mgmt-batch==4.0.0
azure-mgmt-cdn==0.30.3
azure-mgmt-cognitiveservices==1.0.0
azure-mgmt-compute==1.0.0
azure-mgmt-containerregistry==0.2.1
azure-mgmt-datalake-analytics==0.1.6
azure-mgmt-datalake-nspkg==2.0.0
azure-mgmt-datalake-store==0.1.6
azure-mgmt-devtestlabs==2.0.0
azure-mgmt-dns==1.0.1
azure-mgmt-documentdb==0.1.3
azure-mgmt-iothub==0.2.2
azure-mgmt-keyvault==0.31.0
azure-mgmt-logic==2.1.0
azure-mgmt-monitor==0.2.1
azure-mgmt-network==1.0.0
azure-mgmt-nspkg==2.0.0
azure-mgmt-rdbms==0.1.0
azure-mgmt-redis==4.1.0
azure-mgmt-resource==1.1.0
azure-mgmt-scheduler==1.1.3
azure-mgmt-sql==0.5.3
azure-mgmt-storage==1.0.0
azure-mgmt-trafficmanager==0.30.0
azure-mgmt-web==0.32.0
azure-nspkg==2.0.0
azure-servicebus==0.21.1
azure-servicefabric==5.6.130
azure-servicemanagement-legacy==0.20.6
azure-storage==0.34.3
azure-storage-blob==0.37.0
azure-storage-common==0.37.0
azure-storage-file==0.37.0
azure-storage-nspkg==2.0.0
msrestazure==0.4.14

推荐答案

pip install azure时,您安装了azure-storage 0.34.3(教程1).当您遵循第二个教程时,您安装了azure-storage-blob 0.37.0.这是您遇到问题的地方,名称空间中的0.37.0发生了重大突破:

When you pip install azure, you installed azure-storage 0.34.3 (tutorial 1). When you followed the second tutorial, you installed azure-storage-blob 0.37.0. This is where you got issues, there is massive breaking changes in 0.37.0 in the namespaces:

https://github.com/Azure/azure-storage-python/blob/master/BreakingChanges.md#version-0370

在ChangeLog中看到azure-storage< = 0.36与azure-storage-blob> = 0.37不兼容.您以0.37.0版本无声地替换了0.34.3的某些代码文件.

See in the ChangeLog that azure-storage <= 0.36 is incompatible with azure-storage-blob >= 0.37. You silently replaced some code file of 0.34.3 by 0.37.0 version.

在您的第二次测试中,您说过:

In you second test, you said you did:

pip3 install azure-storage-blob
pip3 install azure

软件包仍然不兼容,但是您以相反的顺序进行操作,这次您用0.34.3压碎了0.37.0版本.这就是它起作用的原因.

Package are still incompatible, but you did it in a reverse order, where you crushed your 0.37.0 version with the 0.34.3 one this time. It's why it works.

TLDR,有人需要更新django-storages以支持azure-storage-blob> = 0.37.0.同时,坚持azure-storage< = 0.36,完全不要安装azure-storage-blob.

TLDR, someone needs to update django-storages to support azure-storage-blob >= 0.37.0. In the mean time, stick to azure-storage <= 0.36 and DON'T install azure-storage-blob at all.

这篇关于ImportError:使用Azure后端时无法导入名称"BlobService"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:15