Pip install to custom target directory and exclude specific dependencies

前端 未结 3 1875
野的像风
野的像风 2021-02-07 03:12

I\'m looking for a method to use pip or similiar to install a list of python packages to a custom target directory (ex./mypath/python/pkgs/ ), but also exclude/blacklist

相关标签:
3条回答
  • 2021-02-07 03:35

    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.txt you'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.

    0 讨论(0)
  • 2021-02-07 03:43

    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 pypkgs
    
    0 讨论(0)
  • 2021-02-07 03:51

    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.

    0 讨论(0)
提交回复
热议问题