【发布时间】: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文件,我删除了它,我可以毫无问题地运行!谢谢!
-
好的。到时候我会回答,如果你不介意的话,以备日后参考。