Richard
Richard

Reputation: 61519

Install latest compatible version of package with pip

I'm trying to install NumPy with PIP 9.0.1 (Python 3.3):

/opt/python/cp33-cp33m/bin/pip install 'numpy<2,>=1.7'

PIP merrily gathers numpy-1.12 and then dies because numpy-1.11 is the last version that supported Python 3.3.

Collecting numpy
  Using cached numpy-1.12.1.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-4jvhwz/numpy/setup.py", line 34, in <module>
        raise RuntimeError("Python version 2.7 or >= 3.4 required.")
    RuntimeError: Python version 2.7 or >= 3.4 required.

How can I have pip install the latest compatible version of a package?

Naturally, I could figure this out manually. But this code's in a batch script with a large number of Python distributions (I'm building manylinux wheels), so only a programmatic solution is suitable.

Upvotes: 3

Views: 5739

Answers (1)

Richard
Richard

Reputation: 61519

There may not be a way to have PIP does this automagically, but one can use strings like the following to restrict what is installed for particular versions of Python:

numpy>=1.7,<2; python_version > '3.4'
numpy>=1.7,<1.12; python_version < '3.4'

Further details are here.

Upvotes: 1

Related Questions