如何设置pip默认从镜像仓库下载?
How to setup pip to download from mirror repository by default?
我被迫从本地镜像 PyPi 存储库下载 python 包。我通过使用 -i
和 --trusted-host
选项来做到这一点。整个安装命令如下所示:
pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com package_name
每次都必须输入这些选项有点烦人(实际上这些选项很长 URL)。我尝试创建 get_package.bat 文件(我正在处理 Windows 10),内容如下:
pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%1"
它工作得很好,虽然当我想执行 pip search 命令时,它被证明是无用的,因为它有硬编码的 install
命令并且无法与 [=16 一起使用它=].
有什么方法可以设置 pip 默认从镜像仓库下载,这样我就可以执行 pip install package_name
或 pip search package_name
而无需任何其他选项?
最终我可以尝试制作包含 2 个参数的 .bat 文件:
pip %1 -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%2"
但我想知道是否有更多 "elegant" 方法可以做到这一点。
在用户或全局级别使用 pip config。我有 /etc/pip.conf
配置如下:
[global]
index=https://my-company/nexus/repository/pypi-group/pypi
index-url=https://my-company/nexus/repository/pypi-group/simple
trusted-host=my-company
但您可以在用户或全局级别使用 pip config
配置它,例如:
pip config --user set global.index https://my-company/nexus/repository/pypi-group/pypi
pip config --user set global.index-url https://my-company/nexus/repository/pypi-group/simple
pip config --user set global.trusted-host my-company
#注意事项
--index-url
被 pip install 使用
--index
被 pip search 使用
使用 pip3 config list -v
获取您的 pip.conf 所在位置的列表。然后转到其中一个位置(我更喜欢用户)并添加您的 URL。
该文件应如下所示,如果为空则添加行。
[global]
index-url=https://pypi.org/simple
extra-index-url=<your_url>
如果你想让 pip 先查看你的 URL,然后在上面的选项中切换 url 的位置。
[global]
index-url=<your_url>
extra-index-url=https://pypi.org/simple
我被迫从本地镜像 PyPi 存储库下载 python 包。我通过使用 -i
和 --trusted-host
选项来做到这一点。整个安装命令如下所示:
pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com package_name
每次都必须输入这些选项有点烦人(实际上这些选项很长 URL)。我尝试创建 get_package.bat 文件(我正在处理 Windows 10),内容如下:
pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%1"
它工作得很好,虽然当我想执行 pip search 命令时,它被证明是无用的,因为它有硬编码的 install
命令并且无法与 [=16 一起使用它=].
有什么方法可以设置 pip 默认从镜像仓库下载,这样我就可以执行 pip install package_name
或 pip search package_name
而无需任何其他选项?
最终我可以尝试制作包含 2 个参数的 .bat 文件:
pip %1 -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%2"
但我想知道是否有更多 "elegant" 方法可以做到这一点。
在用户或全局级别使用 pip config。我有 /etc/pip.conf
配置如下:
[global]
index=https://my-company/nexus/repository/pypi-group/pypi
index-url=https://my-company/nexus/repository/pypi-group/simple
trusted-host=my-company
但您可以在用户或全局级别使用 pip config
配置它,例如:
pip config --user set global.index https://my-company/nexus/repository/pypi-group/pypi
pip config --user set global.index-url https://my-company/nexus/repository/pypi-group/simple
pip config --user set global.trusted-host my-company
#注意事项
--index-url
被 pip install 使用
--index
被 pip search 使用
使用 pip3 config list -v
获取您的 pip.conf 所在位置的列表。然后转到其中一个位置(我更喜欢用户)并添加您的 URL。
该文件应如下所示,如果为空则添加行。
[global]
index-url=https://pypi.org/simple
extra-index-url=<your_url>
如果你想让 pip 先查看你的 URL,然后在上面的选项中切换 url 的位置。
[global]
index-url=<your_url>
extra-index-url=https://pypi.org/simple