玩点python卡在pip安装包上了,我用的是pycharm,在它的交互命令行里使用
python -m pip install --upgrade pip
始终报错!
Traceback (most recent call last):
File "d:\soft\python3.7\lib\site-packages\pip\_vendor\urllib3\response.py", line 331, in _error_catcher
yield
File "d:\soft\python3.7\lib\site-packages\pip\_vendor\urllib3\response.py", line 413, in read
data = self._fp.read(amt)
File "d:\soft\python3.7\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read
data = self.__fp.read(amt)
File "d:\soft\python3.7\lib\http\client.py", line 447, in read
n = self.readinto(b)
File "d:\soft\python3.7\lib\http\client.py", line 491, in readinto
n = self.fp.readinto(b)
File "d:\soft\python3.7\lib\socket.py", line 589, in readinto
return self._sock.recv_into(b)
File "d:\soft\python3.7\lib\ssl.py", line 1052, in recv_into
return self.read(nbytes, buffer)
File "d:\soft\python3.7\lib\ssl.py", line 911, in read
return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
从错误上分析显然是下载超时了,那么怎么解决呢?肯定去找国内的镜像资源啊!
于是我网上搜索了一番,终于找到了一个好用的:
python -m pip install --upgrade pip -i https://pypi.douban.com/simple
OMG!看到success我真的是内牛满面啊!
怎么使用pip国内镜像安装第三方库呢?
临时使用
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
国内源:
清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
永久使用:
Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)
内容如下:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com
windows下,直接在user目录中创建一个pip目录,如:C:\Users\zhangsan\pip,新建文件pip.ini。内容同上。