首页 > 解决方案 > 无法使用 pip 安装软件包

问题描述

我的构建机器没有互联网连接。所以我在 nexus 中创建了名为“proxy_repo”的代理存储库,它指向https://pypi.org/。并在构建机器中创建了 ~/.pip/pip.config 。

https://pypi.org/允许通过nexus从构建机器访问。

pip.conf 的内容如下

[global]
trusted-host=MyPrivate-nexusrepo.com
index = https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/pypi
index-url = https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/simple

当我执行任何 pip 命令时,说“pip -v install django”,我总是遇到错误。有人可以帮忙吗?

    Collecting django
  1 location(s) to search for versions of django:
  * https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/simple/django/
  Getting page https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/simple/django/
  Looking up "https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/simple/django/" in the cache
  No cache entry available
  Starting new HTTPS connection (1): MyPrivate-nexusrepo.com
  "GET /content/repositories/proxy_repo/simple/django/ HTTP/1.1" 404 None
  Could not fetch URL https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/simple/django/: 404 Client Error: Not Found for url: https://MyPrivate-nexusrepo.com/content/repositories/proxy_repo/simple/django/ - skipping
  Could not find a version that satisfies the requirement django (from versions: )
Cleaning up...
No matching distribution found for django

标签: pythonpipnexus

解决方案


经常让在受限环境中运行的人绊倒的一件事是,必须允许通过公司防火墙访问这两个服务器:

https://pypi.org/

https://files.pythonhosted.org/

这样做的原因是对第一个 URL 的请求通常会重定向到第二个请求的内容。


推荐阅读