简体   繁体   English

为什么 pip install requirements.txt 安装额外的包?

[英]Why does pip install requirements.txt install extra packages?

I have a repository with an inflated requirements.tx that I'd like to clean up.我有一个我想清理的有膨胀的 requirements.tx 的存储库。 Using pipreqs I've set my requirements.txt to be a minimal set of packages need for my repository.使用pipreqs我已将我的 requirements.txt 设置为我的存储库所需的最小软件包集。 To test this, I setup a virtualenv to install the packages and then run all my unit tests to make sure they're satisfactory.为了测试这一点,我设置了一个 virtualenv 来安装包,然后运行我所有的单元测试以确保它们令人满意。

virtualenv temp_venv --no-site-packages
source temp_venv/bin/activate
pip install -r requirements.txt

Which runs fine, but I see that a whole bunch of extra packages are collected and installed.运行良好,但我看到收集并安装了一大堆额外的软件包。 Why?为什么? Are these identified as needed by required packages, and thus installed?这些是否被所需的软件包识别为需要,并因此安装? If so, should I then include them in the requirements.txt?如果是这样,我应该将它们包含在 requirements.txt 中吗?

Yes.是的。 The packages are dependencies of your dependencies​.包是您的依赖项的依赖项。

But no, you should not specify them directly.但是不,您不应该直接指定它们。 Automatic tools know to download dependencies recursively and it would significantly add to maintenance overhead.自动工具知道递归下载依赖项,这会显着增加维护开销。

This might have been because of the dependencies of your written libs in requirements.txt .这可能是因为您在requirements.txt编写的库的依赖关系。 For ex: if you have written scipy as requirement numpy will also be installed because scipy is dependent on numpy .例如:如果您已将scipy编写为要求numpy也将被安装,因为scipy依赖于numpy

Well, for me the above answers were not the case.好吧,对我来说,上述答案并非如此。 Pip install was installing extra packages not in requirements.txt . Pip install 正在安装不在 requirements.txt 中的额外包。 The solution was:解决方案是:

Run conda create -n venv_name and conda activate venv_name, where venv_name is the name of your virtual environment.运行 conda create -n venv_name 和 conda activate venv_name,其中 venv_name 是您的虚拟环境的名称。

Run conda install pip.运行 conda install pip。 This will install pip to your venv directory.这会将 pip 安装到您的 venv 目录。

Then run pip install -r requeriments.txt然后运行 ​​pip install -r requeriments.txt

The above answer was adapted from here: Using Pip to install packages to Anaconda Environment以上答案改编自这里: Using Pip to install packages to Anaconda Environment

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM