如何更换pip3、brew国内镜像源详细教程 (mac)

======

什么是镜像

为什么叫镜像,是因为镜像站每隔一段时间(几分钟)便会使自己和国外源保持同步,维持和国外源一模一样的软件资源列表,就像照镜子一样(即它从国外下载,我们从它那下载,它是我们的中间媒介)

除了python第三方库下载工具pip,node.js等众多编程语言也可以设置为国内镜像,另外homebrew也可以设置更换镜像源

为什么要使用镜像源

Python的服务器是在国外的,但因为国外官方pypi经常被墙,导致我们用pip3安装模版库是速度极慢,所以我们最好是将自己使用的pip源更换一下,解决被墙导致的装不上库的烦恼
在这里插入图片描述

国内常用镜像源

清华大学     https://pypi.tuna.tsinghua.edu.cn/simple/ 
阿里云       http://mirrors.aliyun.com/pypi/simple/ 
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/ 
豆瓣(douban) http://pypi.douban.com/simple/ 
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

推荐使用清华大学镜像源,清华大学开源镜像站是专门有个社团在运营的,所以是非常可靠的,而且每隔5分钟同步一次

清华大学镜像站官网

pip临时使用镜像源

原始源:https://pypi.python.org/simple

只需在使用pip3的时候加参数-i https://pypi.tuna.tsinghua.edu.cn/simple
即可从清华大学镜像站安装python第三方库

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple gevent

这样就可以从清华大学镜像站去安装gevent库,可以看到速度快得飞起(9.2MB/S)
在这里插入图片描述

一劳永逸更换pip镜像源

Mac用户只需在终端输入

pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

可以看到设置写到了/Users/macos/.config/pip/pip.conf文件中(这个文件原来是没有的)

在这里插入图片描述
安装jieba库,测试成功!
在这里插入图片描述

一劳永逸更换PyCharm镜像源

在这里插入图片描述
安装示例:
在这里插入图片描述

参考资料

======

Mac下brew更换国内镜像源

brew 是一个很好地Mac下管理应用包的工具,可是第一次安装后直接使用时,下载和更新很慢,这是因为brew的镜像源在国外,我们的网络访问会很慢,不过我们可以修改镜像源为国内

使用清华镜像源

官方使用说明

在终端一次运行如下每一行代码

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

brew update

在使用过最后brew update后,需要等待一部分时间,大概一分钟,如果看见终端上方一直在变化就离成功不远了,最后会在终端中显示更新信息,就算是大功告成了

复原

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git

git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git

git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git

brew update
发布了308 篇原创文章 · 获赞 149 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/qq_43827595/article/details/104222999
今日推荐