当前位置: 首页 > news >正文

关于python更换永久镜像源

在Python中更换永久镜像源主要有两种方式:pip镜像源和conda镜像源。以下是详细的配置方法:

1. pip镜像源配置

方法一:使用命令直接配置(推荐)

# 清华镜像源
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple# 或者使用阿里云镜像源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/# 或者使用中科大镜像源
pip config set global.index-url https://pypi.mirrors.ustc.edu.cn/simple/

方法二:手动创建配置文件

Windows系统:

# 在用户目录下创建pip文件夹和pip.ini文件
# 路径:%USERPROFILE%\pip\pip.ini

Linux/Mac系统:

# 在用户目录下创建.pip文件夹和pip.conf文件
# 路径:~/.pip/pip.conf

配置文件内容:

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

2. conda镜像源配置

方法一:使用命令配置

# 添加清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/# 设置搜索时显示通道地址
conda config --set show_channel_urls yes# 移除默认源(可选)
conda config --remove channels defaults# 查看当前配置
conda config --show

方法二:直接编辑.condarc文件

在用户目录下创建或编辑.condarc文件:

Windows: C:\Users\用户名\.condarc
Linux/Mac: ~/.condarc

channels:- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
show_channel_urls: true
ssl_verify: true

3. 常用镜像源地址

pip镜像源:

  • 清华https://pypi.tuna.tsinghua.edu.cn/simple
  • 阿里云https://mirrors.aliyun.com/pypi/simple/
  • 中科大https://pypi.mirrors.ustc.edu.cn/simple/
  • 豆瓣https://pypi.douban.com/simple/
  • 华为云https://repo.huaweicloud.com/repository/pypi/simple/

conda镜像源:

  • 清华https://mirrors.tuna.tsinghua.edu.cn/anaconda/
  • 中科大https://mirrors.ustc.edu.cn/anaconda/

4. 验证配置

配置完成后,可以通过以下命令验证:

# 查看pip配置
pip config list# 查看conda配置
conda config --show# 测试安装包(pip)
pip install requests -v# 测试安装包(conda)
conda install numpy -v

5. 恢复默认源

如果需要恢复默认源:

# pip恢复默认
pip config unset global.index-url# conda恢复默认
conda config --remove-key channels

选择离你地理位置较近的镜像源可以获得更好的下载速度。清华镜像源在国内访问速度通常比较稳定。

http://www.zskr.cn/news/66168.html

相关文章:

  • 2025年电力在线监测系统推荐制造商:高性价比供应商与工厂深
  • 2025年国内防爆接地箱供应商推荐:接地箱定制靠谱企业有哪些
  • 实用指南:攻防世界-cat_cat_new(任意文件读取、Linux敏感文件、flask-session伪造)
  • 2025简历撰写网站TOP5权威推荐:资质齐全信誉好的简历平
  • `pytest + YAML + Allure` 的接口自动化测试框架是业界广泛运用的组合
  • 2025年口碑好的儿童保温杯/设计感保温杯实力厂家TOP推荐榜
  • AI元人文构想:未来的算法规制——从“代码律法”到“价值共生”
  • 2025年比较好的打包箱高评价厂家推荐榜
  • 2025年比较好的加装电梯TOP品牌厂家排行榜
  • 2025年比较好的双层保温饭盒厂家实力及用户口碑排行榜
  • 2025年热门的日本留学签证/日本留学官方认可榜
  • 2025年江浙沪老牌美术高中推荐:美术高中服务怎么联系?哪家
  • 2025年度十大混凝土密封固化剂专业供应商排行榜,新测评精选
  • 2025年质量好的吨袋包装机厂家最新实力排行
  • CentOS7环境下的yum源配置问题
  • 代码随想录Day1_数组
  • 靠谱的混凝土密封固化剂厂家TOP5权威推荐:定制与服务双优企
  • 2025年比较好的隔热服生产厂家
  • [极客大挑战 2019]BabySQL 1 WP
  • 2025年优质的搬家搬运公司/吊装搬运公司推荐排行榜
  • 《网络流的一些建模方法》阅读笔记
  • 2025年有哪些知名的四川水库大坝安全监测热门品牌榜
  • markdown 详解
  • 2025年质量好的PC/ABS改性工程塑料/PC/PBT改性工程塑料TOP品牌厂家排行榜
  • 2025年比较好的直立锁边金属屋面/铝镁锰金属屋面厂家最新推荐排行榜
  • 2025年知名的水泵控制配电箱厂家最新推荐权威榜
  • 2025年知名的实木板用户好评厂家排行
  • 2025年比较好的耐酸涂料厂家最新实力排行
  • 大模型预训练过程中的 MinHash 学习笔记
  • NOI Plus 2025 坠机