我被迫从本地镜像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文件(我在Windows10上工作):
pip install -i https://sampleurl.com/pypi-remote/simple --trusted-host sample.host.com "%1"它工作得非常好,尽管当我想执行pip search命令时,它被证明是无用的,因为它有硬编码的install命令,并且没有办法在search中使用它。
有没有什么方法可以设置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"但我想知道是否有更“优雅”的方式来做到这一点。
发布于 2020-03-23 22:11:51
在用户或全局级别使用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使用
发布于 2020-03-23 22:27:14
使用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/simplehttps://stackoverflow.com/questions/60814982
复制相似问题