Pip install to custom target directory and exclude

2019-03-25 05:28发布

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 specific dependencies.

I want to exclude specific dependencies since they are already met from a different install path (e.g. an anaconda install). I don't have the privilege of adding packages to the default python installation (nor do I want to).

I'm currently use the -r and -t options of pip. But have not found a way to exclude specific packages.

A pip command like this is would be ideal:

pip install --log pip.log -r req.txt -t /mypath/pypkgs/ --exclude exclude.txt

--no-deps is not an option since I need some of the dependencies.

I'm currently pursuing a python script to do pip installs that include dependencies I don't need via:

pip install --log pip.log -r req.txt -t /mypath/python/pkgs/

and then (automatically) remove the unneeded dependencies after the pip install finishes.

I hoping some combination of pip commands can achieve what I'm looking for some straightforward away. I'm using pip 7.1.2. Thanks!

Similar, yet I'm not upgrading and want to specify a target path:

pip: upgrade package without upgrading particular dependency

标签: python pip
2条回答
看我几分像从前
2楼-- · 2019-03-25 05:49

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.

查看更多
Rolldiameter
3楼-- · 2019-03-25 05:57

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.

查看更多
登录 后发表回答