【问题标题】:boto3 AttributeError: 'module' object has no attribute 'client'boto3 AttributeError:“模块”对象没有属性“客户端”
【发布时间】:2021-05-31 23:37:16
【问题描述】:

我正在使用 Python 2.7 和 boto3 版本,但无法导入 boto3 库。

我的 Python 路径是

/Library/Frameworks/Python.framework/Versions/2.7/bin/python

当我往下看时

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages

我看到 boto3 已安装。但我不断收到此错误

 import boto3
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto3/__init__.py", line 16, in <module>
    from boto3.session import Session
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/boto3/session.py", line 14, in <module>
    import copy
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/copy.py", line 60, in <module>
    from org.python.core import PyStringMap
  File "/Users/user/git_repos/aws-boto3/org.py", line 7, in <module>
    client = boto3.client('organizations')
AttributeError: 'module' object has no attribute 'client'

Python 版本:2.7

boto3 版本:1.13.13

botocore 版本:1.16.13

我错过了什么?

这里是代码

import boto3

print('hello')

请注意,我可以从 python 命令行导入 boto3,但在运行 python hello.py 时会失败

【问题讨论】:

  • 你能把代码显示在你想用boto3的地方吗?
  • 我的工作目录中没有 boto3.py
  • @Marcin 添加了代码
  • 有趣的发现,这是另一个python文件,我删除了它,我可以毫无问题地运行!谢谢!
  • 好的。到时候我会回答,如果你不介意的话,以备日后参考。

标签: python boto3


【解决方案1】:

根据 cmets 中的讨论,该问题原来是由于存在一些不需要的文件:

/Users/user/git_repos/aws-boto3/org.py

删除文件是问题的解决方案。

【讨论】:

  • 你是如何找到罪魁祸首的文件
  • @JamesWierzba 嗨。它在问题的错误消息中。
【解决方案2】:

sudo find / -type f -name *boto* 2&gt;&gt;/dev/null - 将帮助获取此类文件并移动或重命名 boto* 以外的其他名称。从而解决问题。

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 1970-01-01
    • 2019-04-28
    • 2019-09-10
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多