pip安装模块时下载很慢,怎么办?

pip 安装模块时下载很慢,怎么办?

默认情况下 pip 使用的是国外的镜像,在下载的时候速度非常慢,此时我们可以使用国内的镜像
系统:macOS,其他系统仅供参考

  • 可以直接在 pip 命令中使用 -i 参数来临时指定所使用的镜像,清华大学镜像:https://pypi.tuna.tsinghua.edu.cn/simple

    pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
    
  • 以上命令只对当前安装指令有用,如果不想每次都要携带-i参数,需要修改配置文件来配置pip的全局镜像

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

    该指令会在特定目录下生成配置文 ,并告诉你配置文件的路径。macOS的路径为:/Users/username/.config/pip/pip.conf
    内容为:

    [global]
    index-url=https://pypi.tuna.tsinghua.edu.cn/simple

    手动写配置文件/Users/username/.config/pip/pip.conf,也是一样的,如果没有对应的文件夹和文件,需要手动创建

镜像源

  • 清华大学: https://pypi.tuna.tsinghua.edu.cn/simple
  • 中国科学技术大学 : https://pypi.mirrors.ustc.edu.cn/simple
  • 豆瓣:http://pypi.douban.com/simple
  • 阿里云:http://mirrors.aliyun.com/pypi/simple
  • 官方镜像:https://pypi.org/simple

参考资料

参考资料1: https://blog.51cto.com/u_15127521/4239706
参考资料2: https://www.runoob.com/w3cnote/pip-cn-mirror.html

你可能感兴趣的:(编程问题集,pip,python,开发语言)