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 官方源。

相关推荐
猫头虎1 天前
如何解决 pip install -r requirements.txt 本地轮子路径 ‘./packages/xxx.whl’ 不存在 问题
开发语言·网络·python·r语言·pip·gpu算力·国产
sweethhheart1 天前
【typora激活使用】mac操作方式
前端·数据库·macos
库奇噜啦呼1 天前
【iOS】简单的四则运算
macos·ios·cocoa
HoJunjie2 天前
macOS sequoia 15.7.1 源码安装node14,并加入nvm管理教程
macos·node.js
心灵宝贝2 天前
Principal v6.15 中文汉化版安装教程|Mac .dmg 文件安装步骤详解
macos
你好龙卷风!!!2 天前
mac | Windows 本地部署 Seata1.7.0,Nacos 作为配置中心、注册中心,MySQL 存储信息
windows·mysql·macos
源文雨2 天前
MacOS 下 Warp ping 局域网设备报错 ping: sendto: No route to host 的解决方法
运维·网络协议·安全·macos·网络安全·ping
liulilittle2 天前
macOS 内核路由表操作:直接 API 编程指南
网络·c++·macos·策略模式·路由·route·通信
QQ12958455043 天前
Mac添加全局变量
开发语言·macos
Everbrilliant894 天前
Xcode上编译调试ffmpeg
macos·ffmpeg·xcode·ffmpeg源码编译工具·xcode调试ffmpeg源码·ffmpeg工具环境变量配置