本文介绍了我可以仅使用pip来使直接安装的软件包保持最新状态吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何列出我直接用pip安装的软件包,从而省去了由此产生的任何依赖关系?

How do I list packages that I have directly installed with pip, omitting any dependences that have been installed as a result?

我有一个运行过的virtualenv,像这样的命令

I have a virtualenv in which I've run, commands like

$ pip install A B C
$ pip install X Y Z

因此,我不仅安装了A,B,C,X,Y和Z,而且还安装了依赖项p,q,r,s,t,u,v和w.但是查看任何给定的软件包,我都无法回忆起它是否是我直接安装的.我想将直接安装的软件包保留在此venv中,并使用类似的

as a result of which I have installed not only A, B, C, X, Y, and Z, but also dependences p, q, r, s, t, u, v, and w. But looking at any given package, I can't recall whether it was something I installed directly or not. I would like to keep the directly installed packages in this venv uptodate with something like

$ pip install -U --directly-installed

具有以下效果的

that has the effect of

$ pip install -U A B C X Y Z

是否有办法仅使直接安装的软件包保持最新状态(仅按那些软件包的要求更新其依赖性)?

Is there a way to keep only the directly installed packages explicitly up to date (updating their dependences only as required by those packages)?

推荐答案

在工作中,我们手动处理直接安装的软件包的列表.也就是说,如果我们需要一个包,则将其添加到requirements.txt并运行

At the job we handle the lists of directly installed packages manually. That is, if we need a package we add it to requirements.txt and run

pip install -r requirements.txt

之后,我们运行

pip freeze > requirements-freezed.txt

保存软件包和依赖项的完整列表.当我们需要重新创建虚拟环境时,我们运行

to save the entire list of packages and dependencies. When we need to recreate a virtual environment we run

pip install -r requirements-freezed.txt

您的仅升级直接安装的软件包的任务将是

Your task to upgrade only directly installed packages would be

pip install -U -r requirements.txt
pip freeze > requirements-freezed.txt

这篇关于我可以仅使用pip来使直接安装的软件包保持最新状态吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 19:02