3

I'm using python's virtual environment (python3 -m venv venv) and pip with requirements.txt. I need to use a package (python-particle) which has a dependency on a very old version of requests (2.7.0). I want to use a more recent version of requests (2.25.0 or later), but because python-particle is explicitly calling out "requests==2.7.0" I get an error when trying to use a later version of requests.

Is there a way to tell pip that the user requested version takes priority? Alternatively, is there a way to tell pip to do dependency resolution for all packages except one?

Things I've tried...

  1. I saw:

setup.py & pip: override one of the dependency's sub-dependency from requirements.txt

$ more requirements.txt 
pexpect>=3.3
python-dateutil>=2.4.2
pytz>=2015.4
six>=1.15.0
python-particle>=0.2

$ more constraints.txt 
requests>=2.25.0

but when I tried that I still got the error:

ERROR: Cannot install -r requirements.txt (line 5) because these package versions have conflicting dependencies.

The conflict is caused by:
    python-particle 0.2 depends on requests==2.7.0
    The user requested (constraint) requests>=2.25.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies

The version of pip that I'm using is:

$ pip --version
pip 21.3.1 from /home/xyzzy/src/tools/venv/lib/python3.9/site-packages/pip (python 3.9)
  1. I also tried using --no-deps for just the one dependency (python-particle), but that didn't work. My requirements.txt for this attempt:
pexpect>=3.3
python-dateutil>=2.4.2
pytz>=2015.4
requests>=2.25.0
six>=1.15.0
python-particle>=0.2 --install-option="--no-deps"

The error message from pip:

ERROR: Cannot install -r requirements.txt (line 6) and requests>=2.25.0 because these package versions have conflicting dependencies.

The conflict is caused by:
    The user requested requests>=2.25.0
    python-particle 0.2 depends on requests==2.7.0

To fix this you could try to:
1. loosen the range of package versions you've specified
2. remove package versions to allow pip attempt to solve the dependency conflict

ERROR: ResolutionImpossible: for help visit https://pip.pypa.io/en/latest/user_guide/#fixing-conflicting-dependencies
CharlesS
  • 31
  • 1
  • 1
    Unfortunately since this project [uses the package metadata to pin dependencies](https://github.com/DarkSector/python-particle/blob/b3d6db780afb12629d5613315de1775b94dbeb38/setup.py#L17-L22), there's nothing you can really do but ignore the conflict and install packages explicitly. Overconstraining in the package metadata is almost always a mistake, so it might be worth a ticket to the project maintainers asking them not to do that. Although, this project looks inactive (no significant changes for 6 years), you might be better off finding an alternative. – wim Dec 13 '21 at 22:36

1 Answers1

0

Maybe use the --no-deps flag to install particle and then install the rest of requirements.txt normally?

pip install python-particle>=0.2
pip uninstall requests
pip install -r requirements.txt (after removing python-particle from this file)

With this method you will need to install every particle dependency other than requests yourself, or you can try this

pip install python-particle>=0.2
pip uninstall requests
pip install -r requirements.txt (again, no particle in this file)

OranShuster
  • 476
  • 2
  • 12