Python 作为 pip 本地服务器的 Nexus 存储库管理器无法正常工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41801306/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 01:38:21  来源:igfitidea点击:

Nexus repository manager as pip local server not working properly

pythonpipnexuslocalserver

提问by jaysonpryde

A local nexus server has been setup as our pip local server. I'm trying to install a sample/test class (inherits) using the said local server. Uploading to the local server is successful, but installing using this command:

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

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

Resulted to this:

结果是这样:

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

I also tried these commands, but the results are the same:

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

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

Here're the contents of my ~/.pypirc:

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

[distutils]
index-servers =
    nexus
    pypi

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

[pypi]
...

Here're the contents my ~/.config/pip/pip.conf

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

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

As mentioned, uploading using below command is successful:

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

python setup.py sdist upload -r nexus

Response from the nexus server is here (i.e. signifies upload was successfull):

来自 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

Contents of the setup.py are the basic details:

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 = [],
)

Any ideas on how to resolve this and make the pip install work? Thanks in advance!

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

回答by jaysonpryde

In case someone has encountered the same issue and is interested for a solution, here are two things I did.

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

1. Execute pip using this:

1. 使用以下命令执行 pip:

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

The -v and --trusted-host parameters are optional

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

2. Move your ~/.config/pip/pip.conf to ~/.pip/pip.conf and execute:

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

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

Only challenge encountered with #2 is pip will always connect to the nexus server. So in case I want to connect to pypi.org, I have to rename the pip.conf first.

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

Hope this helps someone!

希望这可以帮助某人!

回答by Rotareti

I ran into the same problem. I used the following steps to solve it. It works flawlessly now.

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

In the following steps replace pypi-mwwith your private nexus pypi registry name.

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

Add Nexus user with all necessary privileges

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

Create a new role. Filter all privileges by your pypi-registry name and add them all. Apply the new role to your user (you can fine-grain priveleges later):

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

enter image description here

在此处输入图片说明

Edit .pypirc for upload credentials

编辑 .pypirc 以获取上传凭据

Put this into ~/.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

Edit pip.conf for download credentials

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

Put this into ~/.pip/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:[email protected]/repository/pypi-mw/simple/
trusted-host = my-private-registry.com

Try it out

试试看

If everything works like it should, you now have the option to upload your packages to pypilike this:

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

python setup.py bdist_wheel upload

Or to your private registry:

或到您的私人注册表:

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

To install a package you can run the usual command:

要安装软件包,您可以运行通常的命令:

pip install mypackage --user 

It should now search both registries (pypiand pypi-mw) for your package.

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

回答by Kyrremann

I have encountered the same issue, and I resolved it by adding pypip-read and pypip-browse role to my anonymous user on Nexus.

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