【问题标题】:Nexus repository manager as pip local server not working properlyNexus 存储库管理器作为 pip 本地服务器无法正常工作
【发布时间】:2017-06-07 15:57:48
【问题描述】:

已将本地 nexus 服务器设置为我们的 pip 本地服务器。 我正在尝试使用所述本地服务器安装示例/测试类(继承)。 上传到本地服务器成功,但是使用这个命令安装:

pip install -i http://<nexus-ip>:8081/repository/pypi-all/pypi inherits

结果是这样的:

  Could not find a version that satisfies the requirement inherits 
  (from versions: )
  No matching distribution found for inherits

我也试过这些命令,但结果都是一样的:

pip install inherits
pip install -i http://<nexus-ip>:8081/repository/pypi-all/pypi inherits-0.1
pip install -i http://<nexus-ip>:8081/repository/pypi-all/pypi inherits==0.1

这是我的 ~/.pypirc 的内容:

[distutils]
index-servers =
    nexus
    pypi

[nexus]
username: my-username
password: mypassword
repository: http://<nexus-ip>:8081/nexus/repository/pypi-internal/

[pypi]
...

这是我的 ~/.config/pip/pip.conf 的内容

[global]
index = http://<nexus-ip>:8081/repository/pypi-all/pypi
index-url = http://<nexus-ip>:8081/repository/pypi-all/simple

如前所述,使用以下命令上传成功:

python setup.py sdist upload -r nexus

来自 nexus 服务器的响应在这里(即表示上传成功):

creating inherits-0.1
creating inherits-0.1/inherits
creating inherits-0.1/inherits.egg-info
copying files to inherits-0.1...
copying setup.cfg -> inherits-0.1
copying setup.py -> inherits-0.1
copying inherits/__init__.py -> inherits-0.1/inherits
copying inherits/addmult.py -> inherits-0.1/inherits
copying inherits/inherits.py -> inherits-0.1/inherits
copying inherits/subdiv.py -> inherits-0.1/inherits
copying inherits.egg-info/PKG-INFO -> inherits-0.1/inherits.egg-info
copying inherits.egg-info/SOURCES.txt -> inherits-0.1/inherits.egg-info
copying inherits.egg-info/dependency_links.txt -> inherits-0.1/inherits.egg-info
copying inherits.egg-info/top_level.txt -> inherits-0.1/inherits.egg-info
Writing inherits-0.1/setup.cfg
Creating tar archive
removing 'inherits-0.1' (and everything under it)
running upload
Submitting dist/inherits-0.1.tar.gz to http://<nexus-ip>:8081/nexus/repository/pypi-internal/
Server response (200): OK

setup.py 的内容是基本的细节:

#!/usr/bin/env python

import os
import sys

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

requires = []

setup( 
    name = "inherits",
    packages = ["inherits"],
    version = '0.1',
    description = 'Example inherits package',
    #url = "",
    #download_url = "",
    author = "Jayson Pryde",
    classifiers = [],
)

关于如何解决这个问题并使 pip 安装工作的任何想法?提前致谢!

【问题讨论】:

  • 尝试使用带有--verbose 标志的pip install 命令以获取更多信息?

标签: python pip nexus localserver


【解决方案1】:

如果有人遇到同样的问题并对解决方案感兴趣,我做了以下两件事。

1.使用这个执行点子:

pip install inherits -i http://<nexus-ip>:8081/nexus/repository/pypi-all/simple -v --trusted-host <nexus-ip>

-v 和 --trusted-host 参数是可选的

2。将你的 ~/.config/pip/pip.conf 移动到 ~/.pip/pip.conf 并执行:

pip install inherits -v —trusted-host <nexus-ip>

#2 遇到的唯一挑战是 pip 将始终连接到 nexus 服务器。所以如果我想连接到 pypi.org,我必须先重命名 pip.conf。

希望这对某人有所帮助!

【讨论】:

  • 你使用的是哪个版本的 Nexus,遇到同样的问题
  • 只是强调:在选项#1 中使用/simple 而不是/pypi 很重要
  • @AlexFedulov 的评论其实是关键
【解决方案2】:

我遇到了同样的问题。我使用以下步骤来解决它。现在可以完美运行了。

在以下步骤中,将 pypi-mw 替换为您的私有 nexus pypi 注册表名称。

添加具有所有必要权限的 Nexus 用户

创建一个新角色。按您的 pypi-registry 名称过滤所有权限并将它们全部添加。将新角色应用到您的用户(您可以稍后细化权限):

编辑 .pypirc 以获取上传凭据

把这个放到~/.pypirc

[distutils]
index-servers =
    pypi
    pypi-mw

[pypi]
repository: https://pypi.python.org/pypi
username: peter

[pypi-mw]
repository: https://my-private-registry.com/repository/pypi-mw/
username: peter

编辑 pip.conf 以获取下载凭据

把这个放到~/.pip/pip.conf:

[global]
index = https://pypi.python.org/pypi/
index-url=https://pypi.python.org/simple/
extra-index-url=https://MY-NEXUS-USER:MY-NEXUS-PW@my-private-registry.com/repository/pypi-mw/simple/
trusted-host = my-private-registry.com

试试看

如果一切正常,您现在可以选择将您的包上传到pypi,如下所示:

python setup.py bdist_wheel upload

或到您的私人注册表:

python setup.py bdist_wheel upload -r "pypi-mw"

要安装一个包,你可以运行通常的命令:

pip install mypackage --user 

它现在应该在两个注册表(pypipypi-mw)中搜索您的包。

【讨论】:

    【解决方案3】:

    我遇到了同样的问题,我通过在 Nexus 上为我的匿名用户添加 pypip-read 和 pypip-browse 角色解决了这个问题。

    【讨论】:

      【解决方案4】:

      Windows

      中使用 nexus 存储库配置 pip

      在文件夹%APPDATA%/pip/pip.ini 中创建pip.ini,在您的情况下转到您自己的%APPDATA% 文件夹,然后在pip 文件夹下创建一个文本文件pip.ini

      在我的本地 m/c 中,%APPDATA%C:\Users\username\AppData\Roaming&gt;

      pip.ini中添加以下行

      [global]
      trusted-host=nexus.example.com:8443
      index = https://nexus.example.com/repository/pypi-group/pypi
      index-url = https://nexus.example.com/repository/pypi-group/simple
      no-cache-dir = false
      

      然后你可以从你的 windows 命令提示符运行 pip 命令

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-03-13
        • 2013-03-22
        • 1970-01-01
        • 1970-01-01
        • 2012-01-20
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多