我正在运行Python3.6.5并使用pipenv来安装请求。要使用'pipenv shell'测试安装I进入env,然后在下一个提示符下键入python。然后我输入以下代码:
Rs-MacBook-Pro:spacy myname$ pipenv shell
Spawning environment shell (/bin/bash). Use 'exit' to leave.
bash-3.2$ . /Users/myname/.local/share/virtualenvs/spacy- JBK2xTM0/bin/activate (spacy-JBK2xTM0) bash-3.2$ python
Python 3.6.5 (default, Mar 30 2018, 06:41:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> response = requests.get('https://httpbin.org/ip')
>>> print('Your IP is {0}'.format(response.json()['origin']))
我得到了很好的回应。
我使用相同的三行代码并将它们放入由PyCharm或IDLE组成的脚本(requests.py)中,当我运行脚本时,我得到以下错误:
Rs-MacBook-Pro:spacy myname$ pipenv run python ~/requests.py
Traceback (most recent call last):
File "/Users/myname/requests.py", line 1, in <module>
import requests
File "/Users/myname/requests.py", line 2, in <module>
response = requests.get('https://httpbin.org/ip')
AttributeError: module 'requests' has no attribute 'get'
任何想法我做错了什么?谢谢。