在这段代码中,我正在导入boto3模块,但是我的问题显然与该模块无关。
我可以从终端导入模块,但是从python脚本运行时,它无法正常运行。我通过一个简单的pip安装程序进行了安装;我认为这是模块正常工作所需要做的。然后,我检查了模块的位置,以确保我的python路径包括该位置。为什么会这样?
Luke-3589:~ luketimberlake$ pip install boto3
Requirement already satisfied: six>=1.5 in /usr/local/lib/python2.7/site-packages (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore<1.13.0,>=1.12.163->boto3) (1.12.0)
Luke-3589:~ luketimberlake$ python
Python 2.7.16 (default, Apr 12 2019, 15:32:52)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect, boto3
>>> s3 = boto3.client('s3')
>>> inspect.getfile(boto3)
'/usr/local/lib/python2.7/site-packages/boto3/__init__.pyc'
>>> exit()
Luke-3589:~ luketimberlake$ echo $PYTHONPATH
:/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages:/usr/local/lib/python2.7/site-packages/boto3
Luke-3589:~ luketimberlake$ python Desktop/aws.py
Traceback (most recent call last):
File "Desktop/aws.py", line 1, in <module>
import boto3
File "/Users/luketimberlake/Desktop/boto3.py", line 3, in <module>
s3 = boto3.client('s3')
AttributeError: 'module' object has no attribute 'client'