Python 如何使用 setup.py 安装托管在私有 PyPI 中的包?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18828805/
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-19 11:58:28  来源:igfitidea点击:

How can I install packages hosted in a private PyPI using setup.py?

pythonsetuptoolspypi

提问by Balthazar Rouberol

I'm trying to write the setup.pyinstall file for a private project, which has both public and private dependencies. The public ones are hosted on PyPI, whereas the private ones are hosted on a server running simplepypi.

我正在尝试setup.py为一个私有项目编写安装文件,该项目具有公共和私有依赖项。公共的托管在 PyPI 上,而私有的托管在运行simplepypi的服务器上。

I would like both public and private dependencies to be resolved and fetched during installation.

我希望在安装过程中解析和获取公共和私有依赖项。

I thus added my dependencies to setup.py:

因此,我将我的依赖项添加到setup.py

setup(
    ...
    install_requires = [
        # public dependencies
        'argparse==1.2.1',
        'beautifulsoup4==4.1.3',
        'lxml==3.1.0',
        'mongoengine==0.8.2',
        'pymongo==2.5.2',
        'requests==1.1.0',
        'Cython==0.18',
        # private dependencies
        'myprivatepackage1',
        'myprivatepackage2'
    ],
    dependency_links=['http://pypi.myserver.com/packages'],
    ...
)

I build the package tarball using the command python setup.py sdistand install it in an activated virtualenv using pip install --verbose path/to/tarball.tar.gz.

我使用命令构建包 tarballpython setup.py sdist并使用pip install --verbose path/to/tarball.tar.gz.

However, the pip log lines do not mention my private PyPI server anywhere, and https://pypi.python.org/simple/seems to have been queried twice.

但是,pip 日志行在任何地方都没有提到我的私人 PyPI 服务器,而且https://pypi.python.org/simple/似乎已经被查询了两次。

Running setup.py egg_info for package from file:///home/b/code/mapado/mypackage/dist/mypackage-0.5.1.tar.gz
    running egg_info
    creating pip-egg-info/mypackage.egg-info
    writing requirements to pip-egg-info/mypackage.egg-info/requires.txt
    writing pip-egg-info/mypackage.egg-info/PKG-INFO
    writing top-level names to pip-egg-info/mypackage.egg-info/top_level.txt
    writing dependency_links to pip-egg-info/mypackage.egg-info/dependency_links.txt
    writing manifest file 'pip-egg-info/mypackage.egg-info/SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'pip-egg-info/mypackage.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'pip-egg-info/mypackage.egg-info/SOURCES.txt'
Downloading/unpacking myprivatepackage (from mypackage==0.5.1)
  Could not fetch URL https://pypi.python.org/simple/myprivatepackage/: HTTP Error 404: Not Found (myprivatepackage does not have any releases)
  Will skip URL https://pypi.python.org/simple/myprivatepackage/ when looking for download links for myprivatepackage (from mypackage==0.5.1)
  Could not fetch URL https://pypi.python.org/simple/myprivatepackage/: HTTP Error 404: Not Found (myprivatepackage does not have any releases)
  Will skip URL https://pypi.python.org/simple/myprivatepackage/ when looking for download links for myprivatepackage (from mypackage==0.5.1)
  Could not find any downloads that satisfy the requirement myprivatepackage (from mypackage==0.5.1)
Cleaning up...

What am I missing?

我错过了什么?

Thank you very much!

非常感谢!

采纳答案by Balthazar Rouberol

it looks like you didnt specify your host like the doc of simplepysaid you need to setup your ~/.pypircwith the good hostname like

看起来你没有像simplepy的文档那样指定你的主机说你需要~/.pypirc用好的主机名来设置你的主机名

To use it run "simplepypi". You can upload packages by:

Modify your ~/.pypirc so it looks like:

    [distutils]
    index-servers =
        pypi
        local

    [local]
    username: <whatever>
    password: <doesn't matter, see above>
    repository: http://127.0.0.1:8000

    [pypi]
    ...

要使用它,请运行“simplepypi”。您可以通过以下方式上传包:

Modify your ~/.pypirc so it looks like:

    [distutils]
    index-servers =
        pypi
        local

    [local]
    username: <whatever>
    password: <doesn't matter, see above>
    repository: http://127.0.0.1:8000

    [pypi]
    ...

then you'll upload your package on it

然后你会上传你的包裹

python setup.py sdist upload -r local

and could install it from there

并且可以从那里安装它

pip install -i http://127.0.0.1:8000/pypi <your favorite package>

Hope this will help.

希望这会有所帮助。

回答by r89m

dependency_linksis ignored by default (at least in pip 9.0.1)

dependency_links默认情况下被忽略(至少在 pip 9.0.1 中)

In order for it to reach out to your sever you need to add --process-dependency-links

为了让它联系到您的服务器,您需要添加 --process-dependency-links

I believe pip 10 will bring a new mechanism, but for now this has got it working for me

我相信pip 10 会带来一个新的机制,但现在这对我有用

I also had to update dependency_linksto include the package name, for example:

我还必须更新dependency_links以包含包名称,例如:

dependency_links=[
    "http://internal-pyp:5678/simple/your_package_name"
]