I am working on a project with packaging==21.3
specified in the requirements.txt
file. I want to install black, but if I do so, it installs the latest version of black which depends on packaging>=22.0
, so it updates packaging.
$ pip install black
...
Collecting packaging>=22.0 (from black)
Using cached packaging-25.0-py3-none-any.whl.metadata (3.3 kB)
...
Installing collected packages: packaging, black
Attempting uninstall: packaging
Found existing installation: packaging 21.3
Uninstalling packaging-21.3:
Successfully uninstalled packaging-21.3
Successfully installed black-25.1.0 packaging-25.0
I would prefer not to modify the current packages as it's a new system and I'm not familiar enough with it to know if this will change any behaviour.
So I want to install a version of black that is compatible with packaging==21.3
, but the only way I can think of is to work backwards version by version until I find one.
Is there a way to retrieve the latest version of black that is compatible with this version of packaging?
You can create a constraints file
echo "packaging==21.3" > constraints.txt
Then installing like
pip install black -c constraints.txt
Otherwise in a single command you can do
pip install black packaging==21.3