首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么Python包不能从我的个人PyPI服务器上安装?

为什么Python包不能从我的个人PyPI服务器上安装?
EN

Stack Overflow用户
提问于 2019-03-01 05:01:58
回答 3查看 3.8K关注 0票数 4

我已经在Debian9/Nginx机器上创建了一个个人PyPI“包”服务器,这样我就可以使我的服务器构建具有确定性。我固定我的所有Python包,并需要确保每当我需要重建我的电子商务服务器时,我的Python包的确切版本以及它们的子依赖项总是可用。

我使用pip2pi包将所需的包填充到此服务器中。但是,当我在客户端服务器上运行"pip install“命令来安装我的软件包时,我得到了以下错误:

代码语言:javascript
复制
Looking in indexes: https://packages.example.com/simple
Collecting Django==1.8.4 (from -r requirements.txt (line 2))
Collecting django-extensions==1.5.7 (from -r requirements.txt (line 3))
  Could not find a version that satisfies the requirement django-extensions==1.5.7 (from -r requirements.txt (line 3)) (from versions: )
No matching distribution found for django-extensions==1.5.7 (from -r requirements.txt (line 3))

我的需求文件中有大约40个包,所以这只是一个发生情况的示例。将安装Django包,但使用django-extensions包的pip将失败。

如果我在任何客户端服务器上运行此命令,我会得到上面所示的错误:

代码语言:javascript
复制
pip install -r requirements.txt

需求文件如下所示:

代码语言:javascript
复制
-i https://packages.example.com/simple
Django==1.8.4
django-extensions==1.5.7
(more packages)

现在,在我的软件包服务器上,软件包根目录/var/www/packages具有以下结构:

代码语言:javascript
复制
# /var/www/packages:
├── Django-1.8.4-py2.py3-none-any.whl
├── django_extensions-1.5.7-py2.py3-none-any.whl
├── simple
    ├── django
    │   ├── Django-1.8.4-py2.py3-none-any.whl -> ../../Django-1.8.4-py2.py3-none-any.whl
    │   └── index.html
    ├── django-extensions
    │   ├── django-extensions-1.5.7-py2.py3-none-any.whl -> ../../django_extensions-1.5.7-py2.py3-none-any.whl
    │   └── index.html
    ├── index.html

此目录结构是使用Pip2pi的pip2tgz命令构建并安装的:

代码语言:javascript
复制
pip2tgz /var/www/packages/ -r requirements.txt

下面是pip2tgz读取的需求输入文件:

代码语言:javascript
复制
-i https://pypi.org/simple
django==1.8.4
django-extensions=1.5.7
(more packages)

包服务器上的nginx根目录设置如下:

代码语言:javascript
复制
server {
    ...
    root /var/www/packages;
    ...
}

我的包服务器上的防火墙设置为允许ping,允许我通过SSH登录,并允许所有http和https连接。

我在客户端服务器上使用Python 3.5.3和pip 19.0.3。

我不确定我做错了什么。pip命令看起来是正确的,但是我想知道pip2pi包是否正确地设置了我的包目录。如果我将客户机需求文件中的索引参数更改为默认值https://pypi.org/simple,则所有包都会恢复,而不会出现错误。

更新1

如果我尝试从命令行而不是通过需求文件安装django-extensions,我仍然得到一个错误:

代码语言:javascript
复制
pip install --index-url=https://packages.example.com/simple/ django-extensions
Looking in indexes: https://packages.example.com/simple/
Collecting django-extensions
  Could not find a version that satisfies the requirement django-extensions (from versions: )
No matching distribution found for django-extensions

在检查我的其他包时,我确实在这里看到了一个模式。每当我尝试安装一个包,其中的轮子文件名包含一个下划线("_"),但根据Python PEP 503,包目录的规范化名称中有一个连字符("-")时,就会出现这个错误。

例如,django-rq失败:

代码语言:javascript
复制
directory: simple/django-rq
file: django_rq-0.9.0-py2.py3-none-any.whl

另一方面,django-redis-cache不会失败:

代码语言:javascript
复制
directory: simple/django-redis-cache
file: django-redis-cache-1.6.5.tar.gz

但另一个不同之处在于,前者是一个轮式文件,而后者是一个tgz文件,所以这可能也是造成这种差异的原因。我会继续调查这个问题。

更新2

根据Ares的建议,我使用verbose选项运行pip install:

代码语言:javascript
复制
pip install --verbose --index-url=https://packages.example.com/simple/ django-rq

下面是错误:

代码语言:javascript
复制
Created temporary directory: /tmp/pip-ephem-wheel-cache-g_hx5tb1
Created temporary directory: /tmp/pip-req-tracker-1bt5psaw
Created requirements tracker '/tmp/pip-req-tracker-1bt5psaw'
Created temporary directory: /tmp/pip-install-dqvtv6ek
Looking in indexes: https://packages.example.com/simple/
Collecting django-rq
  1 location(s) to search for versions of django-rq:
  * https://packages.example.com/simple/django-rq/
  Getting page https://packages.example.com/simple/django-rq/
  Looking up "https://packages.example.com/simple/django-rq/" in the cache
  Request header has "max_age" as 0, cache bypassed
  Starting new HTTPS connection (1): packages.example.com:443
  https://packages.example.com:443 "GET /simple/django-rq/ HTTP/1.1" 304 0
  Analyzing links from page https://packages.example.com/simple/django-rq/
    Skipping link https://packages.example.com/simple/django-rq/django-rq-0.9.0-py2.py3-none-any.whl (from https://packages.example.com/simple/django-rq/); wrong project name (not django-rq)
Cleaning up...
Removed build tracker '/tmp/pip-req-tracker-1bt5psaw'
Exception information:
Traceback (most recent call last):
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/cli/base_command.py", line 179, in main
    status = self.run(options, args)
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/commands/install.py", line 315, in run
    resolver.resolve(requirement_set)
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 131, in resolve
    self._resolve_one(requirement_set, req)
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 294, in _resolve_one
    abstract_dist = self._get_abstract_dist_for(req_to_install)
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/resolve.py", line 242, in _get_abstract_dist_for
    self.require_hashes
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/operations/prepare.py", line 269, in prepare_linked_requirement
    req.populate_link(finder, upgrade_allowed, require_hashes)
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/req/req_install.py", line 196, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/home/flaugher/pip3/venv/lib/python3.5/site-packages/pip/_internal/index.py", line 688, in find_requirement
    'No matching distribution found for %s' % req
pip._internal.exceptions.DistributionNotFound: No matching distribution found for django-rq

关键字出现在第15行,其中显示“跳过链接...错误的项目名称(不是django-rq)”。我不确定它为什么跳过链接。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2019-03-05 02:45:23

看起来pypi-server将最好地满足我的需求。如上所述,它成功地安装了pip2pi失败的包。它的设置并不太复杂,可以通过Nginx或Apache在远程服务器上运行。我发现这篇文章Setting up a PyPI server非常有帮助(尽管它确实有几个拼写错误)。

票数 0
EN

Stack Overflow用户

发布于 2019-03-01 06:39:49

对于我的私有包服务器,唯一有效的方法是--extra-index-url:

代码语言:javascript
复制
--extra-index-url https://foo.redacted.com/
Django
my_other_package

这将首先检查pypi,然后检查您的私人服务器。对调试有帮助的一件事是使用--verbose来显示连接发生了什么。

票数 1
EN

Stack Overflow用户

发布于 2019-03-01 08:52:43

看起来您正在使用的pip2pi项目有错误,并且最近没有维护,有几个关于分发包名称中的点/破折号的公开问题:

Issue with packages with hyphen in the name #84

Fix improper binary filename normalization for packages with hyphens in the names #67

Changed dir2pi to use original file name in file link. #85

我建议你去看看devpi-server

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54934204

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档