macos查询pip默认镜像地址

在 macOS 系统中,查询 pip 的默认镜像地址可以通过以下几种方法:

方法 1:直接通过 pip config list 命令查询

运行以下命令查看当前 pip 的配置(包括镜像地址):

复制代码
pip config list

如果输出中包含 global.index-urlinstall.trusted-host,则显示的是当前配置的镜像地址。例如:

复制代码
global.index-url=https://pypi.tuna.tsinghua.edu.cn/simple
install.trusted-host=pypi.tuna.tsinghua.edu.cn

如果无输出,说明未显式配置镜像,默认使用 PyPI 官方源:

复制代码
https://pypi.org/simple。

方法 2:检查 pip 配置文件

pip 的配置文件优先级为:

  1. 用户级配置~/.pip/pip.conf~/.config/pip/pip.conf

  2. 全局配置/etc/pip.conf

查看配置文件内容:

复制代码
# 查看用户级配置
cat ~/.pip/pip.conf 2>/dev/null || cat ~/.config/pip/pip.conf 2>/dev/null

# 查看全局配置
cat /etc/pip.conf 2>/dev/null

若配置了镜像,会显示类似以下内容:

复制代码
[global]
index-url = https://mirrors.aliyun.com/pypi/simple
trusted-host = mirrors.aliyun.com

方法 3:通过 Python 代码查询(适用于编程场景)

复制代码
from pip._internal.commands.configuration import get_pip_config
config = get_pip_config()
index_url = config.get_value("global.index-url")
print(f"当前镜像地址: {index_url or '默认 PyPI (https://pypi.org/simple)'}")

默认镜像地址

如果未手动配置镜像,pip 默认使用 PyPI 官方源

复制代码
https://pypi.org/simple。

常见国内镜像地址示例

镜像名称 地址
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple
阿里云 https://mirrors.aliyun.com/pypi/simple
华为云 https://repo.huaweicloud.com/repository/pypi/simple
豆瓣 https://pypi.doubanio.com/simple

总结

  • 使用 pip config list 直接查看生效的配置。

  • 检查 ~/.pip/pip.conf/etc/pip.conf 文件。

  • 若未配置镜像,默认地址为 PyPI 官方源。

相关推荐
岁忧3 小时前
macOS配置 GO语言环境
开发语言·macos·golang
岁忧10 小时前
macOS 安装 Homebrew
macos·homebrew
棒棒AIT11 小时前
mac 苹果电脑 Intel 芯片(Mac X86) 安卓虚拟机 Android模拟器 的救命稻草(下载安装指南)
android·游戏·macos·安卓·mac
*愿风载尘*18 小时前
SecureCRT连接密钥交换失败
linux·macos
mCell1 天前
从删库到跑路?这50个Linux命令能保你职业生涯
linux·windows·macos
fhf1 天前
2025年了你会卸载Macbook上的应用吗?
macos·shell
归辞...1 天前
「iOS」——内存五大分区
macos·ios·cocoa
穆雄雄2 天前
备份一下我的 mac mini 的环境变量配置情况
macos
秃然想通2 天前
mac电脑搭载c、c++环境(基于vs code)
macos
归辞...2 天前
「iOS」——GCD其他方法详解
macos·ios·cocoa