277

Is there any way to force install a pip python package ignoring all its dependencies that cannot be satisfied?

(I don't care how "wrong" it is to do so, I just need to do it, any logic and reasoning aside...)

danronmoon
  • 3,814
  • 5
  • 34
  • 56
NeuronQ
  • 7,527
  • 9
  • 42
  • 60
  • 4
    did you try `pip install --no-deps `? – Charlie Parker Sep 22 '20 at 20:36
  • I'd argue that this is correct way to install production requirements from a lock file produced by tools like pip-tools, where you expect all transitive dependencies to already be resolved. – antonagestam May 20 '23 at 21:24
  • A good reason to do so these days is to keep libs in an earlier Docker layer and source install in a later layer. This decreases the time to build Docker images. So it is not "wrong" in that sense. – Greg Smethells Aug 03 '23 at 18:44

4 Answers4

408

pip has a --no-dependencies switch. You should use that.

For more information, run pip install -h, where you'll see this line:

--no-deps, --no-dependencies
                        Ignore package dependencies
Jeff Tratner
  • 16,270
  • 4
  • 47
  • 67
  • 44
    how to pass this within a requirements.txt file? – Austin Aug 03 '15 at 23:27
  • 11
    To run with a requirements.txt, it would be: `pip install --no-deps -r requirements.txt` – Graham Place May 16 '18 at 06:51
  • 1
    Anything like this to prevent installing recommended packages like with `apt-get install --no-install-recommends`? – Connor Jul 12 '18 at 21:23
  • 3
    @Connor there is no equivalent to "recommended packages" in any of the standard Python packaging tools: distutils, setuptools, pip. Setuptools (and pip) has "extras", but they must be explicitly selected and installed by the user. – shadowtalker Oct 18 '18 at 19:51
  • 3
    This doesn't seem to work for a local package. `pip install --no-deps /path/to/package` gives the message "Installing build dependencies" and attempts to install build dependencies. – Ben Caine May 06 '21 at 15:38
  • 1
    @BenCaine try using --no-build-isolation as well, this will turn off the build isolation feature of newer pip versions, which will mean that all build requirements must be present already. – Aaron D Jun 14 '22 at 13:24
  • 1
    it does not work for me... stlil installs dependencies: `pip install --no-deps aequilibrae Collecting aequilibrae Using cached aequilibrae-0.7.7.tar.gz (1.8 MB) Installing build dependencies ... error` – Intelligent-Infrastructure Feb 03 '23 at 11:28
  • Awesome! So this would be suitable for installing from `pip freeze` output, since every required package should already be present? – Ted Brownlow Jun 08 '23 at 16:05
19

Try the following:

pip install --no-deps <LIB_NAME>

or

pip install --no-dependencies <LIB_NAME>

or

pip install --no-deps -r requirements.txt

or

pip install --no-dependencies -r requirements.txt
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323
  • 11
    Doesn't this ignore *all* dependencies? The OP asked for "all it's dependencies *that cannot be satisfied*". It would be good to still install dependencies if possible, and then just skip ones where some kind of problem occurs. – Ben Farmer Oct 05 '22 at 00:07
13

When I was trying install librosa package with pip (pip install librosa), this error appeared:

ERROR: Cannot uninstall 'llvmlite'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.

I tried to remove llvmlite, but pip uninstall could not remove it. So, I used capability of ignore of pip by this code:

pip install librosa --ignore-installed llvmlite

Indeed, you can use this rule for ignoring a package you don't want to consider:

pip install {package you want to install} --ignore-installed {installed package you don't want to consider}
Zim
  • 410
  • 4
  • 13
Hamed Baziyad
  • 1,954
  • 5
  • 27
  • 40
  • 15
    this is not exactly what the op asked for. according to the man page -I, --ignore-installed Ignore the installed packages (reinstalling instead). this flag will explicilty reinstall the specified packages, even if they are installed already – madmuffin Apr 17 '20 at 13:12
  • Is there a way to see which packages will be effected before installing? How about telling `pip` to ignore many packages? – Royi Sep 11 '21 at 12:30
1

I came up to this question looking for a resolution when first package requires foo-lib<=1.1 and second package requires foo-lib>=1.0, so incompatible foo-lib==1.2 is forcefully installed (as the newest) during the installation of a second package.

The version can be additionally limited with pip install {second_package} "foo-lib==1.1". (doc)

Matt G.
  • 31
  • 4