279

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...)

3
  • 4
    did you try pip install --no-deps <LIB>? Sep 22, 2020 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. May 20 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. Aug 3 at 18:44

4 Answers 4

410

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
8
  • 44
    how to pass this within a requirements.txt file?
    – Austin
    Aug 3, 2015 at 23:27
  • 12
    To run with a requirements.txt, it would be: pip install --no-deps -r requirements.txt May 16, 2018 at 6:51
  • 1
    Anything like this to prevent installing recommended packages like with apt-get install --no-install-recommends?
    – Connor
    Jul 12, 2018 at 21:23
  • 4
    @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. Oct 18, 2018 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 6, 2021 at 15:38
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
1
  • 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 5, 2022 at 0: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}
2
  • 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, 2020 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, 2021 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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.