Python指定源安装库
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python指定源安装库相关的知识,希望对你有一定的参考价值。
参考技术A 导出python库命令为:pip3 freeze > filename.txt
三方库方法为:
pip install -r pypy.txt
指定源安装库
pip install 模块名 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip3 install threads -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
python库镜像源
http://mirrors.aliyun.com/pypi/simple/ 阿里云
https://pypi.mirrors.ustc.edu.cn/simple/ 中国科技大学
http://pypi.douban.com/simple/ 豆瓣
https://pypi.tuna.tsinghua.edu.cn/simple/ 清华大学
http://pypi.mirrors.ustc.edu.cn/simple/ 中国科学技术大学
不用pip官方源安装Python扩展库的方法(使用国内的镜像源)
由于众所周知的原因,中国大陆连接很多境外站点都很慢,并且时不时的还会中断,所以很多时候用pip官方源安装Python不仅慢,好不容易等到whl安装包快下载完了,结果连接断开,导致安装失败,真的是让人感觉很恼火。
把自己的IP切换到国外吧,由于代理的原因,又可能出现各种意想不到的网络问题。
最好的方法就是用pip官方源安装Python扩展库的的时候不用官方的源,而用国内的镜像源。
国内的镜像源还是挺多的,常用的有如下这些:
阿里云 https://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 https://pypi.douban.com/simple/
v2ex https://pypi.v2ex.com/simple/
中国科学院 https://pypi.mirrors.opencas.cn/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:https://pypi.hustunique.com/
山东理工大学:https://pypi.sdutlinux.org/
Python官方 https://pypi.python.org/simple/
那么用pip安装Python扩展库时怎么样使用这些源呢?
方法一:
在使用pip安装某个扩展库的时候加上参数-i,示例如下:
pip install -i https://mirrors.aliyun.com/pypi/simple opencv-python==4.4.0.46
方法二:
在使用pip安装扩展库前先手动全局切换镜像源,示例如下:
# 全局手动切换镜像源地址
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
# 切换完成后再用 install 命令安装自己想安装的扩展库
pip install opencv-python==4.4.0.46
以上是关于Python指定源安装库的主要内容,如果未能解决你的问题,请参考以下文章