在通过pip install django下载django时,又一次见惯不过的错误页面,具体如下。似乎已经很多次出现各种错误的情况了,最常见的就是没使用超级管理员账号导致权限不足的,还有就是下载超时的,read timed out,可是我的网络就是这么烂有什么办法啦。(吐槽一下网络,平时上一下外网真的是卡的要骂娘)经过一番探索,学习了各位大神pip -i设置安装源即使用国内镜像源的办法,记录下载方便查用。
直接更换全局镜像源的方法是:
1、在windows文件管理器中输入“ %APPDATA% ”,再进入Roaming\pip,会定位到一个新的目录下(“C:\Users\(用户名)\AppData\Roaming\pip\pip.ini”),在该目录下新建pip文件夹,然后到匹配文件夹中新建一个pip.ini 文件。
2、在新建的 pip.ini 文件中输入以下内容,保存即可。
注意:" index-url " 的内容是镜像源的路径,可以更换
[global] index-url = https://mirrors.aliyun.com/pypi/simple/ [install] trusted-host=mirrors.aliyun.com
也可以临时更换镜像源:
pip install --index https://pypi.mirrors.ustc.edu.cn/simple django
下图为在pycharm软件中更改镜像源的方式。
C:\WINDOWS\system32>pip install django Collecting django Downloading https://files.pythonhosted.org/packages/c6/b7/63d23df1e311ca0d90f41352a9efe7389ba353df95deea5676652e615420/Django-3.0.3-py3-none-any.whl (7.5MB) |▌ | 143kB 9.1kB/s eta 0:13:24ERROR: Exception: Traceback (most recent call last): File "c:\program files\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 397, in _error_catcher yield File "c:\program files\python37\lib\site-packages\pip\_vendor\urllib3\response.py", line 479, in read data = self._fp.read(amt) File "c:\program files\python37\lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 62, in read data = self.__fp.read(amt) File "c:\program files\python37\lib\http\client.py", line 447, in read n = self.readinto(b) File "c:\program files\python37\lib\http\client.py", line 491, in readinto n = self.fp.readinto(b) File "c:\program files\python37\lib\socket.py", line 589, in readinto return self._sock.recv_into(b) File "c:\program files\python37\lib\ssl.py", line 1052, in recv_into return self.read(nbytes, buffer) File "c:\program files\python37\lib\ssl.py", line 911, in read return self._sslobj.read(len, buffer) socket.timeout: The read operation timed out
修改了安装源以后,下载安装顺利。
C:\WINDOWS\system32>pip install --index https://pypi.mirrors.ustc.edu.cn/simple django Looking in indexes: https://pypi.mirrors.ustc.edu.cn/simple Collecting django Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/c6/b7/63d23df1e311ca0d90f41352a9efe7389ba353df95deea5676652e615420/Django-3.0.3-py3-none-any.whl (7.5MB) |████████████████████████████████| 7.5MB 1.1MB/s Collecting pytz (from django) Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB) |████████████████████████████████| 512kB 6.4MB/s Collecting asgiref~=3.2 (from django) Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/a5/cb/5a235b605a9753ebcb2730c75e610fb51c8cab3f01230080a8229fa36adb/asgiref-3.2.3-py2.py3-none-any.whl Collecting sqlparse>=0.2.2 (from django) WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProtocolError('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))': /pypi/web/simple/sqlparse/ Downloading https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl Installing collected packages: pytz, asgiref, sqlparse, django Successfully installed asgiref-3.2.3 django-3.0.3 pytz-2019.3 sqlparse-0.3.0 WARNING: You are using pip version 19.2.2, however version 20.0.2 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
部分国内镜像源:
清华: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/
评论
访客
回复学习了,向大牛学习。
访客
回复学习了,timed out 应该将网络带宽升级到千兆宽带啦,哈哈
访客
回复timed out 应该将网络带宽升级到千兆宽带啦,哈哈