【问题标题】:ImportError: No module named azure.storage.blobImportError:没有名为 azure.storage.blob 的模块
【发布时间】:2018-11-01 18:15:44
【问题描述】:

我正在尝试使用以下代码通过 python 从 Azure 将文件下载到我的本地设备上:

from azure.storage.blob import BlockBlobService
block_blob_service = BlockBlobService(account_name='account_name', 
account_key='mykey')
block_blob_service.get_blob_to_path('container', 'file', 'out-test.csv')

但是,当我运行此代码时,我收到以下错误:

ImportError: No module named azure.storage.blob

从 pip list 的输出截图可以看出,我已经安装了 azure 模块:

C:\Users\hpfc87>pip list
Package              Version
-------------------- ---------
adal                 0.6.0
asn1crypto           0.24.0
azure-common         1.1.11
azure-nspkg          2.0.0
azure-storage        0.36.0
azure-storage-blob   1.1.0
azure-storage-common 1.1.0
azure-storage-file   1.1.0
azure-storage-nspkg  3.0.0
azure-storage-queue  1.1.0

我曾尝试关注以下有关此问题的各种帖子,但我没有运气:

ImportError: No module named azure.storage.blob (when doing syncdb)

https://github.com/Azure/azure-storage-python/issues/262

有什么建议吗?

【问题讨论】:

  • 您是否安装了多个 Python?如果是这样,你确定你用来运行脚本的那个和你用来pip list的那个是一样的吗?
  • 我只有python 2.7
  • 你能试试这个吗? from azure.storage.blob.blockblobservice import * ?
  • 还要确保如果您安装了 64 位版本的新 python 库,您也正在运行 64 位的 python,反之亦然 32 位。
  • 我的错,我刚刚意识到我可能安装了两个版本的 python。我首先安装了python 2.7,然后安装了anaconda来获取spyder和jupyter。这可能会导致安装两个版本吗?我一直在通过 anaconda 使用 spyder 并收到上述错误。当我尝试使用命令行而不是 spyder 运行脚本时,它运行时没有出现错误。

标签: python python-2.7 azure azure-storage azure-blob-storage


【解决方案1】:

总结一下,你的问题是因为你安装的python 2.7版本和Anaconda的python版本冲突造成的。

您安装的软件包应该在 python 2.7 环境中。不过spyder使用的是Anaconda自带的python环境。

命令行使用系统python环境,由path中之前的python环境变量决定。

【讨论】:

    猜你喜欢
    • 2017-01-15
    • 2016-03-28
    • 2013-03-11
    • 2012-12-07
    • 2012-05-23
    • 2019-07-29
    • 2015-07-04
    • 2014-03-15
    • 2017-12-29
    相关资源
    最近更新 更多