python2;用--trusted-host和--extra-index-url pip parse_requirements [英] python2; pip parse_requirements with --trusted-host and --extra-index-url

查看:375
本文介绍了python2;用--trusted-host和--extra-index-url pip parse_requirements的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

install_requires = [str(ir.req) for ir in parse_requirements("requirements.txt", session=PipSession())]

pip install ..但是,这似乎不适用于如下所示的requirements.txt:

with pip install .. However, this does not seem to work with a requirements.txt that looks like this:

--trusted-host blah
--extra-index-url blah2
...

(在pip8.0.0中添加了对--trusted-host的支持). blah的安装失败,因为它抱怨它不是不受信任的主机,就好像它从未处理过第一行一样.

(support for --trusted-host was added in pip8.0.0). The install from blah fails because it complains about it not being an untrusted host as if it never processed the first line.

但是,pip install -r requirements.txt可以完美运行,因此这些选项是正确的.

HOWEVER, pip install -r requirements.txt works perfectly, so these options are correct.

这表示parse_requirements没有执行任何操作. 我的问题:如何仅使用pip install .修复或解决此问题?我可以做些可怕的事情:

This means there is something parse_requirements is not doing. My question is: how do I fix or work around this using only pip install .? I could do something horrendous like:

os.system(pip install -r requirements.txt)
setup(...

在setup.py文件中.

in the setup.py file.

Requires.txt和setup.py的隐式耦合使我感到困惑.除非您自己明确地解析requirements.txt,否则安装程序中的任何内容都不会调用require.txt,但是requirements.txt是非常标准的python约定.

The implicit coupling of requirements.txt and setup.py is confusing to me. Nothing in setup calls requirements.txt unless you explicitly parse requirements.txt yourself, yet requirements.txt is a very standard python convention.

我们正在使用执行pip install .的工具(Cloudify,有时甚至是Chef).我们不能改变这一点.我必须使用--trusted-host和--extra-index-urls作为可插入的程序包来使用它,而不要使用pip.conf.当前,我们正在做os.system技巧.

We are using tools (Cloudify and sometimes Chef) that execute a pip install .. We cannot change this. I have to get this working as a pippable package, with the --trusted-host and --extra-index-urls without using a pip.conf either. Currently we are doing the os.system trick.

推荐答案

关于使用setup.py vrs的文章很多. requirements.txt. Setup.py用于抽象要求. Requirements.txt是针对具体需求的.换句话说,它们有不同的用途. requirements.txt是用于环境的,而setup.py是用于软件包的.因此,setup.py从require.txt读取没有意义,就像deb包从Chef食谱中读取毫无意义. 摘要vrs.具体要求

There has been much written about using setup.py vrs. requirements.txt. Setup.py is for Abstract requirements. Requirements.txt is for concrete requirements. In other words, they serve different purposes. Whereas requirements.txt is for an environment, setup.py is for a package. So it doesn't make sense for a setup.py to read from a requirement.txt just like it wouldn't make sense for a deb package to read from a Chef cookbook. Abstract vrs. Concrete Requirements

人们这样做的原因通常是他们希望支持人们在结帐时使用pip install -r requirements.txt安装软件包,而无需列出其依赖项两次.这是一件很合理的事情,这就是为什么需求文件格式具有启用它的结构,只需制作一个包含."的requirements.txt文件.或"-e".然后pip将自动安装项目及其所有依赖项.

Often the reason people do this is they want to support people installing their package with pip install -r requirements.txt from within a check out without needing to list their dependencies twice. That's a reasonable thing to want which is why the requirements file format has a construct that enables it, simply make a requirements.txt file that contains "." or "-e ." and pip will automatically install the project and all of it's dependencies.

由于pip并非库,因此使用程序中暴露最多的部分是最安全的(我认为).

Since pip is not a library, using the most exposed part of the program is the safest (in my opinion). An alternative to os.system is

import pip
pip.main(['install','-r','requirements.txt'])

这篇关于python2;用--trusted-host和--extra-index-url pip parse_requirements的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆