python的工具包都是要从国外下载到本地,下载速度速度贼慢,而且经常安装失败,解决方法是使用国内的镜像资源进行安装,这里提供两种使用国内镜像资源导包的方法:
方法一
第一种方法就是使用pip install xxx -i url
,这里的url可以是
阿里: https://mirrors.aliyun.com/pypi/simple/
清华: https://pypi.tuna.tsinghua.edu.cn/simple
豆瓣: http://pypi.douban.com/simple/
如使用阿里导入jieba这个包,命令为
pip install jieba -i https://mirrors.aliyun.com/pypi/simple/
方法二
方法二是永久性改变pip的下载源到国内的镜像源,以后只需要像以前一样pip install xxx
就行了
//永久切换到阿里镜像源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
//永久切换到清华镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
//永久切换到豆瓣镜像源
pip config set global.index-url http://pypi.douban.com/simple/
总结
方法二虽然可以一劳永逸,但是不能保证所有的包都有,或者不是最新版的包。方法一虽然麻烦,但是没有永久切换镜像源,如果确实需要最新版的包,还是可以通过pip install xxx
从官方下载到,至于具体使用哪种方式请自行定夺了。