如何在pip冻结生成的需求文件中维护pip安装选项? [英] How to maintain pip install options in requirements file made by pip freeze?

查看:111
本文介绍了如何在pip冻结生成的需求文件中维护pip安装选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 pip需求文件来维护我项目的依赖项列表. /p>

我现在发现自己必须使用pip install --install-option='some-setup.py.option' 安装库,但是pip freeze并没有在我保存在项目requirements.txt中的输出中记录这些选项.这会导致问题,因为在新计算机上使用简单的pip install -r requirements.txt会安装所有依赖项,而不会为此库提供必需的参数,因此我已经失去了简单的往返操作.

所以,我的第二部分问题是:

  • 是否可以通过某种方式在pip冻结输出中维护pip安装选项?
  • 如果没有,是否有办法手动修改需求文件以添加安装选项?如果可以的话,我可以放弃pip freeze的往返特性,并转而手动维护需求文件.我已经查看了文档,但找不到任何帮助.

不必要但可能有趣的细节紧随其后

我想安装 pymongo ,但要安装 eventlet 基于应用程序.

根据需要安装并生成要求.txt:

(test)day@office:~/test$ pip install pymongo --install-option='--no_ext'
Downloading/unpacking pymongo
  Downloading pymongo-2.1.1.tar.gz (199Kb): 199Kb downloaded
  Running setup.py egg_info for package pymongo
Installing collected packages: pymongo
  Running setup.py install for pymongo
Successfully installed pymongo
Cleaning up...
(test)day@office:~/test$ pip freeze >  requirements.txt
(test)day@office:~/test$ cat requirements.txt
bottle==0.10.7
distribute==0.6.10
eventlet==0.9.16
greenlet==0.3.3
lxml==2.3.3
pymongo==2.1.1
simplejson==2.3.2
wsgiref==0.1.2

在新的virtualenv中,尝试从requirements.txt安装相同的项目. pip为pymongo :(

构建C扩展

(test2)day@office:~/test2$ pip install -r requirements.txt 
...
Downloading/unpacking pymongo==2.1.1 (from -r requirements.txt (line 6))
  Downloading pymongo-2.1.1.tar.gz (199Kb): 199Kb downloaded
  Running setup.py egg_info for package pymongo
Installing collected packages: pymongo
  Running setup.py install for pymongo
    building 'bson._cbson' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.6 -c bson/_cbsonmodule.c -o build/temp.linux-i686-2.6/bson/_cbsonmodule.o
...
Successfully installed pymongo
Cleaning up...

更新 问题271 于2011年4月针对pip开通,要求能够在要求中指定每行--install-option的功能.文本.如果您遇到相同的问题,请对该问题进行投票.

解决方案

自7.0版(发布 2015-05-21 ),pip可以从需求文件中解析--install-option--global-option.现在应该可以在requirements.txt中添加以下行:

pymongo==2.1.1 --install-option='--no_ext'

可以在此处找到更多信息和此处.

I use a pip requirements file to maintain a list of dependencies for my projects.

I now find myself having to install a library using pip install --install-option='some-setup.py.option' but pip freeze doesn't record these options in its output which I save in my project's requirements.txt. This causes problems because a simple pip install -r requirements.txt on a new machine installs all the dependencies without supplying the required arguments for this one library, and I've lost the simple round-trip operation.

So, my 2 part question is:

  • Is there a way to maintain pip install options in the pip freeze output somehow?
  • If not, is there a way to manually hack the requirements file to add the install option? I'm ok with losing the round trip nature of pip freeze if I have to, and switching to manual maintenance of the requirements file. I've checked the documentation but couldn't see anything to help.

Unnecessary but possibly interesting details follow

I want to install pymongo but without building the C extension so I can use it asynchronously in an eventlet based app.

Install as desired and build requirements.txt:

(test)day@office:~/test$ pip install pymongo --install-option='--no_ext'
Downloading/unpacking pymongo
  Downloading pymongo-2.1.1.tar.gz (199Kb): 199Kb downloaded
  Running setup.py egg_info for package pymongo
Installing collected packages: pymongo
  Running setup.py install for pymongo
Successfully installed pymongo
Cleaning up...
(test)day@office:~/test$ pip freeze >  requirements.txt
(test)day@office:~/test$ cat requirements.txt
bottle==0.10.7
distribute==0.6.10
eventlet==0.9.16
greenlet==0.3.3
lxml==2.3.3
pymongo==2.1.1
simplejson==2.3.2
wsgiref==0.1.2

In new virtualenv, try to install same project from requirements.txt. pip builds the C extension for pymongo :(

(test2)day@office:~/test2$ pip install -r requirements.txt 
...
Downloading/unpacking pymongo==2.1.1 (from -r requirements.txt (line 6))
  Downloading pymongo-2.1.1.tar.gz (199Kb): 199Kb downloaded
  Running setup.py egg_info for package pymongo
Installing collected packages: pymongo
  Running setup.py install for pymongo
    building 'bson._cbson' extension
    gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Ibson -I/usr/include/python2.6 -c bson/_cbsonmodule.c -o build/temp.linux-i686-2.6/bson/_cbsonmodule.o
...
Successfully installed pymongo
Cleaning up...

Update Issue 271 was opened against pip in April 2011 asking for the ability to specify per-line --install-option in requirements.txt. Please vote for the issue if you have the same problem.

解决方案

Since version 7.0 (released 2015-05-21), pip has the ability to parse --install-option and --global-option from requirement files. It should now be possible to have the following line in your requirements.txt:

pymongo==2.1.1 --install-option='--no_ext'

More information can be found here and here.

这篇关于如何在pip冻结生成的需求文件中维护pip安装选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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