Python设置国内镜像源

萌翻了84个人 / 2024-10-13 / 原文

python官方各版本下载地址:

https://www.python.org/ftp/python/

Python 第三方库国内镜像下载地址

豆瓣

  • https://pypi.douban.com/simple

阿里云

  • https://mirrors.aliyun.com/pypi/simple

清华大学

  • https://pypi.tuna.tsinghua.edu.cn/simple

中国科技大学

  • https://pypi.mirrors.ustc.edu.cn/simple

使用方法为在 pip 命令后加 -i URL 方法,以从阿里云下载 pandas 库为例:

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pandas

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

永久修改,一劳永逸:#

Linux下,修改 ~/.pip/pip.conf (没有就创建一个文件夹及文件。文件夹要加“.”,表示是隐藏文件夹)

内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host=mirrors.aliyun.com

windows下,直接在 %userprofile% 目录中创建一个 pip目录,再新建文件 pip.ini。(例如:C:\Users\WQP\pip\pip.ini)内容同上。