requests 依赖的库都已经安装了.
Requirement not upgraded as not directly required: chardet<3.1.0,>=3.0.2 in d:\p
ython27\lib\site-packages (from requests) (3.0.4)
Requirement not upgraded as not directly required: certifi>=2017.4.17 in d:\pyth
on27\lib\site-packages (from requests) (2018.4.16)
Requirement not upgraded as not directly required: urllib3<1.23,>=1.21.1 in d:\p
ython27\lib\site-packages (from requests) (1.22)
Requirement not upgraded as not directly required: idna<2.7,>=2.5 in d:\python27
\lib\site-packages (from requests) (2.5)
pip install requests -U
提示
Successfully installed requests-2.18.4
pip 版本
pip 10.0.1 from d:\python27\lib\site-packages\pip (python 2.7)
然后我在 python 执行 import requests 报错:
>>> import requests
D:\Python27\lib\site-packages\requests\__init__.py:80: RequestsDependencyWarning
: urllib3 (1.9.1) or chardet (3.0.4) doesn't match a supported version!
RequestsDependencyWarning)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python27\lib\site-packages\requests\__init__.py", line 90, in <module
>
from urllib3.exceptions import DependencyWarning
ImportError: cannot import name DependencyWarning
1
zeyexe 2018-04-21 20:08:56 +08:00
是不是用了 TUNA 的 index,最近他们家的好像有问题。我之前用 TUNA 的镜像遇到 urllib3 的问题,换阿里云的好了。
|
3
AgentK 2018-04-21 21:16:53 +08:00
所以为什么要用 virtualenv
|
4
Hstar 2018-04-21 21:30:11 +08:00
试着执行下 from urllib3.exceptions import DependencyWarning
然后试下能否 import 其他库, 比如一些内建库, 然后装个其他库试试是否是普遍问题 然后检查下当前 path: import sys; print(sys.path) 以前遇到不能 import 基本都是路径问题 |
7
xxbing OP @Hstar
``` from urllib3.exceptions import DependencyWarning ``` ``` Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: cannot import name DependencyWarning ``` ``` import sys,json,urllib3,MySQLdb ``` 都没有错误. ``` import sys; print(sys.path) ``` 返回 ``` ['', 'C:\\Windows\\system32\\python27.zip', 'D:\\Python27\\DLLs', 'D:\\Python27\ \lib', 'D:\\Python27\\lib\\plat-win', 'D:\\Python27\\lib\\lib-tk', 'D:\\Python27 ', 'D:\\Python27\\lib\\site-packages'] ``` |
8
Kilerd 2018-04-21 22:26:14 +08:00 1
Requirement not upgraded as not directly required: urllib3<1.23,>=1.21.1 in d:\p
ython27\lib\site-packages (from requests) (1.22) 首先 requests 里面要求 urllib3 要符合这个条件<1.23,>=1.21.1 D:\Python27\lib\site-packages\requests\__init__.py:80: RequestsDependencyWarning : urllib3 (1.9.1) or chardet (3.0.4) doesn't match a supported version! 你的报错信息是这个。证明安装的 urllib3 是 1.9.1 版本。 所以出错啊。 解决方法: 1 用官方源重装试试。先 pip uninstall requests urllib3 2 手动升级 urllib3 3 试下用 virtualenv / pipenv / pyenv 隔离 py 环境 其实这个问题主要的发生场景是 有一个 package 依赖于 urllib3 较早版本,然后你再安装 requests 的时候会导致依赖冲突,就只有一个 package 可以用了。 |