简体   繁体   中英

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. Using pipreqs I've set my requirements.txt to be a minimal set of packages need for my repository. 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 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?

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 . For ex: if you have written scipy as requirement numpy will also be installed because scipy is dependent on numpy .

Well, for me the above answers were not the case. Pip install was installing extra packages not in 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.

Run conda install pip. This will install pip to your venv directory.

Then run pip install -r requeriments.txt

The above answer was adapted from here: Using Pip to install packages to Anaconda Environment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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