代码之家  ›  专栏  ›  技术社区  ›  Jim

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

  •  1
  • Jim  · 技术社区  · 5 年前

    pip2pi 包裹。但是,当我在客户机服务器上运行“pip install”命令来安装我的包时,我得到了以下错误:

    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))
    

    pip install -r requirements.txt
    

    需求文件如下所示:

    -i https://packages.example.com/simple
    Django==1.8.4
    django-extensions==1.5.7
    (more packages)
    

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

    # /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
    

    pip2tgz /var/www/packages/ -r requirements.txt
    

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

    -i https://pypi.org/simple
    django==1.8.4
    django-extensions=1.5.7
    (more packages)
    

    下面是如何在包服务器上设置nginx根目录:

    server {
        ...
        root /var/www/packages;
        ...
    }
    

    我在客户机服务器上使用python3.5.3和pip19.0.3。

    我不知道我做错了什么。pip命令看起来是正确的,但是我想知道pip2pi包是否正确地设置了我的包目录。如果我将客户需求文件中的index参数更改为默认值, https://pypi.org/simple 还原所有程序包,没有错误。

    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
    

    在检查我的其他包时,我确实看到了一个模式。每当我尝试安装一个程序包时,如果wheel文件名包含下划线(“”)但包目录的规范化名称中包含Python PEP 503中的hypen(“-”),就会出现错误。

    例如,django rq失败:

    directory: simple/django-rq
    file: django_rq-0.9.0-py2.py3-none-any.whl
    

    directory: simple/django-redis-cache
    file: django-redis-cache-1.6.5.tar.gz
    

    但另一个不同之处在于前者是一个wheel文件,而后者是一个tgz文件,所以这也可以解释这个差异。我会继续调查的。

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

    pip install --verbose --index-url=https://packages.example.com/simple/ django-rq
    

    错误如下:

    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
    

    0 回复  |  直到 5 年前
        1
  •  1
  •   Athena Vinod R    5 年前

    --extra-index-url https://foo.redacted.com/
    Django
    my_other_package
    

    --verbose

        2
  •  1
  •   wim    5 年前

    它看起来像 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 相反。

        3
  •  0
  •   Jim    5 年前

    看起来像 pypi-server Setting up a PyPI server 很有帮助(虽然它确实有一些打字错误)。