Pip Install To Custom Target Directory And Exclude Specific Dependencies
Solution 1:
Faced with a similar problem, and using a running bash shell I managed to exclude specific packages with
pip install $(grep -ivE "pkg1|pkg2|pkg3" requirements.txt)
where pkg1 and so on are the names of the packages to exclude.
Solution 2:
I think this essentially can be achieved in several steps, assuming you're using virtualenv or similar...
If you first do a normal
pip freeze > requirements.txtyou'll get all of the transitive dependencies (e.g. not excluding anything.)Now edit requirements.txt, remove the packages you want to exclude...
Finally, in a new environment do
pip install -r requirements.txt -t ... --no-deps. Voila: you've installed the dependencies you wanted while excluding specific ones.
Solution 3:
An approach that takes into account sub-dependencies is to first install the exclude.txt environment, then the req.txt environment, then check the diff and finally install that into the target directory.
Example using virtualenv that will work on GNU/Linux:
virtualenv tmpenv
source tmpenv/bin/activate
pip install -r exclude.txt
pip freeze > exclude-with-deps.txt
pip install -r req.txt
pip freeze > req-with-deps.txt
comm -13 exclude-with-deps.txt req-with-deps.txt >final-req.txt
pip install -r final-req.txt --no-deps -t pypkgsSolution 4:
You can use pip install --no-deps with pip check to exclude specific packages.
A real example of mine is when I installed paddleocr on Jetson Nano, pip kept installing python-opencv for me, which has already installed by myself without using pip, but pip cannot detect it. To stop pip installing python-opencv for me, here are the steps
- use 
pip install --no-deps paddleocrto installpaddleocrwithout its dependencies - use 
pip checkto list unresolved dependencies, reformat the output so that it can be read bypip install -r, then remove the packages you don't want to install (it ispython-opencvin my case), and save it to a file namedfix-deps.txt - use 
pip install --no-deps -r fix-deps.txtto install unresolved dependencies - repeat steps 2 and 3 until the output of 
pip checkonly contains the packages you don't want to install. 
pip install --no-deps and pip check are very useful commands that allow you to resolve the dependencies by yourself when pip cannot do it right for you. The shortcoming of this solution is the output of pip check is designed for humans, it cannot be used by pip install -r directly, so you have to reformat the output manually or use the awk command.
PR and issue have been created for the pip community to make the output of pip check suitable for the pip install to read, but for some reason, they don't think it is a good idea. so I guess this is the best we can do now.
Refs:
Post a Comment for "Pip Install To Custom Target Directory And Exclude Specific Dependencies"