python安装request方法mac_新人求问, mac os 系统,想使用 requests 库,安装后提示成功,但是在 Python import 时显示 name 'request' is ...

用 pip 安装了 requests 库,下面是终端:

wujingyideMacBook:~ my$ sudo pip install requests

Password:

The directory '/Users/my/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/Users/my/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

Collecting requests

Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)

100% |████████████████████████████████| 92kB 92kB/s

Collecting certifi>=2017.4.17 (from requests)

Downloading certifi-2018.1.18-py2.py3-none-any.whl (151kB)

100% |████████████████████████████████| 153kB 210kB/s

Collecting chardet<3.1.0,>=3.0.2 (from requests)

Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB)

100% |████████████████████████████████| 143kB 140kB/s

Collecting idna<2.7,>=2.5 (from requests)

Downloading idna-2.6-py2.py3-none-any.whl (56kB)

100% |████████████████████████████████| 61kB 171kB/s

Collecting urllib3<1.23,>=1.21.1 (from requests)

Downloading urllib3-1.22-py2.py3-none-any.whl (132kB)

100% |████████████████████████████████| 133kB 159kB/s

Installing collected packages: certifi, chardet, idna, urllib3, requests

Successfully installed certifi-2018.1.18 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22

上面显示安装成功后,在终端启用了 python,但是还是显示 name 'request' is not defined

wujingyideMacBook:~ my$ python

Python 2.7.10 (default, Jul 15 2017, 17:16:57)

[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin

Type "help", "copyright", "credits" or "license" for more information.

import requests

r = request.get("http://www.baidu.com")

Traceback (most recent call last):

File "", line 1, in

NameError: name 'request' is not defined

下面这段是在 pycharm 里显示的错误:

import requests

r = requests.get("http://www.baidu.com")

r.status_code

r.encoding = 'utf-8'

r.text

Traceback (most recent call last):

File "/Users/my/PycharmProjects/demo/learn.py", line 1, in

import requests

ImportError: No module named requests

Process finished with exit code 1

但是在 pycharm 的 progect interpreter 里明明添加了 requests 库

本人用的是 mac,自带的 python2.7,目前安装了 pycharm oc,之前安装过 anaconda,又卸载了,不知道是不是电脑坏境有问题,求解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值