Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipenv ignore sub-dependency

Tags:

python

pipenv

Using Pipenv, how do I prevent pipenv install from installing certain sub-dependencies (dependencies of dependencies)?

Specifically, I want to install the tensorflow pacakge as a dependency of my pacakge, but I don't want to install the tensorboard package, which is a dependency of tensorflow even though it's not really needed.

I can kind of work around the problem by removing the tensorboard package after installation, but that does not remove all the packages that tensorboard package pulled in as dependencies (like werkzeug).

A more complete but complex solution would be to look at pipenv graph to figure out which dependencies only appear under tensorboard (and are not needed by anything else), but maybe there is a simpler solution?

like image 699
pydora Avatar asked Apr 09 '26 02:04

pydora


1 Answers

Currently, pipenv does not support this. There are a couple of workarounds (as you have alluded to):

  1. Add the following script to Pipfile, and then run pipenv run pip-install:
    [scripts]
    # requirements.txt identifies the package to install w/o deps, e.g. tensorflow
    pip-install  = "pip install --no-deps -r requirements.txt"
    

OR 2. Set PIP_NO_DEPS=1 in .env, and then call pip explicitly to install the parent package:

pipenv run pip install tensorflow

With each of these cases, you'll still need to add the required dependencies to Pipfile / Pipfile.lock; pipdeptree and jq can be useful for this:

# note: jq must be installed using the system package manager
pipenv install "pipdeptree"

pipdeptree --json-tree |  # format the dependency tree as JSON
  jq '.[] | select(.key == "tensorflow") |  # filter to the target package
    .dependencies[] | select( .key != "tensorboard" ) |  # select all deps except tensorboard
    "\( .key )\( .required_version )"' |  # and output the req to install with pipenv
  xargs pipenv install

A third option is to fork tensorflow, remove the tensorboard dependency, and pip install git+https://github.com/the-fork-of/tensorflow.git.

like image 69
Bryant Avatar answered Apr 11 '26 16:04

Bryant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!