告诉 pip 安装需求文件中列出的软件包的依赖项 [英] tell pip to install the dependencies of packages listed in a requirement file

查看:47
本文介绍了告诉 pip 安装需求文件中列出的软件包的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发 Django Web 应用程序时,我有一个需要安装在 virtualenv 中的软件包列表.说:

Developing a Django web app, I have a list of packages I need to install in a virtualenv. Say:

Django==1.3.1
--extra-index-url=http://dist.pinaxproject.com/dev/
Pinax==0.9b1.dev10
git+git://github.com/pinax/pinax-theme-bootstrap.git@cff4f5bbe9f87f0c67ee9ada9aa8ae82978f9890
# and other packages

最初我在开发过程中一个一个地手动安装它们.这安装了所需的依赖项,我最终在部署应用程序之前使用了 pip freeze.

Initially I installed them manually, one by one, along the development. This installed the required dependencies and I finally used pip freeze before deploying the app.

问题是,当我升级了一些软件包时,一些依赖项不再使用或不再需要,但它们一直被 pip freeze 列出.

Problem is, as I upgraded some packages, some dependencies are no longer used nor required but they keep being listed by pip freeze.

现在,我想以这种方式设置一个新的 virtualenv:

Now, I'd like to set up a new virtualenv this way:

  • 将需要的包(没有它们的依赖)放在一个需求文件中,
    manual-requirements.txt
  • 安装它们及其依赖项
    pip install -r manual-requirement.txt(← 问题,这个没有安装依赖)
  • 冻结完整的virtualenv
    pip freeze -r manual-requirements.txt >full-requirements.txt
    并部署.
  • put the needed packages (without their dependencies) in a requirement file,
    like manual-requirements.txt
  • install them with their dependencies
    pip install -r manual-requirement.txt (← problem, this does not install the dependencies)
  • freeze the full virtualenv
    pip freeze -r manual-requirements.txt > full-requirements.txt
    and deploy.

没有在新的 virtualenv 中手动重新安装软件包以获得它们的依赖关系的任何方法吗?这很容易出错,我想自动化从不再需要的旧依赖项中清除 virtualenv 的过程.

Any way to do this without manually re-installing the packages in a new virtualenv to get their dependencies ? This would be error-prone and I'd like to automate the process of cleaning the virtualenv from no-longer-needed old dependencies.

实际上,pip 确实安装了需求文件中未明确列出的依赖项,即使 文档 告诉我们这些文件是扁平的.我错了我希望安装哪些依赖项.我会让任何对 pip 不安装所有依赖项有疑问的人提出这个问题.

edit: actually, pip does install dependencies not explicitly listed in the requirement file, even if the documentation tells us that such files are flat. I was wrong about which dependencies i expected to be installed. I'll let this question for anyone in doubt about pip not installing all dependencies.

推荐答案

鉴于您对问题的评论(您说对单个包执行安装按预期工作),我建议您循环查看您的需求文件.在 bash 中:

Given your comment to the question (where you say that executing the install for a single package works as expected), I would suggest looping over your requirement file. In bash:

#!/bin/sh
while read p; do
  pip install $p
done < requirements.pip

HTH!

这篇关于告诉 pip 安装需求文件中列出的软件包的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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