在 setup.py 中使用额外的 python 包索引 url

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

Using an extra python package index url with setup.py

pythonpackagingsetup.pypypi

提问by Jeremy

Is there a way to use an extra python package index (ala pip --extra-index-url pypi.example.org mypackage) with setup.pyso that running python setup.py installcan find the packages hosted on pypi.example.org?

有没有办法使用额外的 python 包索引 (ala pip --extra-index-url pypi.example.org mypackage)setup.py以便运行python setup.py install可以找到托管的包pypi.example.org

采纳答案by Heston Liebowitz

If you're the package maintainer, and you want to host one or more dependencies for your package somewhere other than PyPi, you can use the dependency_linksoption of setuptoolsin your distribution's setup.pyfile. This allows you to provide an explicit location where your package can be located.

如果您是包维护者,并且希望在 PyPi 以外的某个地方为包托管一个或多个依赖项,则可以使用发行版文件中的dependency_links选项。这允许您提供可以定位您的包的明​​确位置。setuptoolssetup.py

For example:

例如:

from setuptools import setup

setup(
    name='somepackage',
    install_requires=[
        'somedep'
    ],
    dependency_links=[
        'https://pypi.example.org/pypi/somedep/'
    ]
    # ...
)

If you host your own index server, you'll need to provide links to the pages containing the actual download links for each egg, not the page listing all of the packages (e.g. https://pypi.example.org/pypi/somedep/, not https://pypi.example.org/)

如果您托管自己的索引服务器,则需要提供指向包含每个蛋的实际下载链接的页面的链接,而不是列出所有包的页面(例如https://pypi.example.org/pypi/somedep/,不是https://pypi.example.org/

回答by Lovato

As far as I know, you cant do that. You need to tell pip this, or by passing a parameter like you mentioned, or by setting this on the user environment.

据我所知,你不能那样做。你需要告诉 pip 这个,或者通过像你提到的那样传递一个参数,或者通过在用户环境中设置它。

Check my ~/.pip/pip.conf:

检查我的 ~/.pip/pip.conf:

[global]
download_cache = ~/.cache/pip
index-url = http://user:[email protected]:80/simple
timeout = 300

In this case, my local pypiserver also proxies all packages from pypi.python.org, so I dont need to add a 2nd entry.

在这种情况下,我的本地 pypiserver 也代理来自 pypi.python.org 的所有包,所以我不需要添加第二个条目。

回答by Tommy

You can include --extra-index-urlsin a requirements.txt file. See: http://pip.readthedocs.org/en/0.8.3/requirement-format.html

您可以包含--extra-index-urls在 requirements.txt 文件中。请参阅:http: //pip.readthedocs.org/en/0.8.3/requirement-format.html

回答by TomDotTom

setuptoolsuses easy_installunder the hood.

setuptools幕后使用easy_install

It relies on either setup.cfgor ~/.pydistutils.cfgas documented here.

它依赖于setup.cfg~/.pydistutils.cfg,如此处所述

Extra paths to packagescan be defined in either of these files with the find_links. You can override the registry url with index_urlbut cannot supply an extra-index-url. Example below inspired by the docs:

可以使用find_links在这些文件中的任何一个中定义包的额外路径。您可以使用index_url覆盖注册表 url,但不能提供extra-index-url。以下示例受文档启发:

[easy_install]
find_links = http://mypackages.example.com/somedir/
             http://turbogears.org/download/
             http://peak.telecommunity.com/dist/
index-url = https://mypi.example.com

回答by miku

The following worked for me (develop, not install):

以下对我有用(开发,而不是安装):

$ python setup.py develop --index-url https://x.com/n/r/pypi-proxy/simple

Where https://x.com/n/r/pypi-proxy/simpleis a local PyPI repository.

https://x.com/n/r/pypi-proxy/simple本地 PyPI 存储库在哪里。

回答by NOZUONOHIGH

Found solution when using Dockerfile:

使用 Dockerfile 时找到的解决方案:

RUN cd flask-mongoengine-0.9.5 && \
    /bin/echo -e [easy_install]\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple >> setup.cfg && \
    python setup.py install

Which /bin/echo -e [easy_install]\\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simplewill output:

/bin/echo -e [easy_install]\\nindex-url = https://pypi.tuna.tsinghua.edu.cn/simple将输出:

[easy_install]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple