如何为包管理器uv配置类似pip的索引URL
如何配置uv从私有Python仓库拉取包?
使用pip安装Python包时,可通过配置使其从私有仓库拉取包。例如大型企业出于安全考虑,会将包存放在私有仓库并仅信任该资源,此时在macOS/Linux创建pip.conf、Windows创建pip.ini,配置如下:
[global] index-url=https://path/to/private/repo/simple1 extra-index-url=https://path/to/private/repo/simple2现使用uv作为包管理器,需完成相同配置,该如何操作?
一、持久化配置(通过配置文件)
uv使用uv.toml作为统一配置文件,不同系统的默认路径如下:
- macOS/Linux:
~/.config/uv/uv.toml - Windows:
%APPDATA%\uv\uv.toml
在配置文件中添加以下内容,即可实现和pip一致的私有仓库配置:
[registry.index] url = "https://path/to/private/repo/simple1" extra_urls = ["https://path/to/private/repo/simple2"]
如果需要完全禁用公共PyPI,仅信任私有仓库,可以追加default = false:
[registry.index] url = "https://path/to/private/repo/simple1" extra_urls = ["https://path/to/private/repo/simple2"] default = false
二、临时配置(环境变量)
若仅需单次使用私有仓库,无需修改配置文件,可通过环境变量指定:
- macOS/Linux(bash/zsh):
export UV_INDEX_URL="https://path/to/private/repo/simple1" export UV_EXTRA_INDEX_URLS="https://path/to/private/repo/simple2" - Windows(PowerShell):
$env:UV_INDEX_URL = "https://path/to/private/repo/simple1" $env:UV_EXTRA_INDEX_URLS = "https://path/to/private/repo/simple2"
三、单次命令指定(参数方式)
执行uv安装命令时,直接通过参数传递仓库地址:
uv install <你的包名> --index-url https://path/to/private/repo/simple1 --extra-index-url https://path/to/private/repo/simple2
内容的提问来源于stack exchange,提问作者Ghasem
相关产品推荐
相关产品推荐

