Unable to downgrade version of Python package by `pip install -I`

Viewed 3375

To temporary workaround a compatibility issue, I tried to downgrade version of Python package arrow from 0.17.0 to 0.13.2.

On a particular server I was unable to, as the below command calls to install 0.13.2 but ends up install back 0.17.0. If remove the virtual environment, and generate a new one and freshly install 0.13.2, it works OK.

I also tested on a virtual machine, and the downgrade works OK without this symptom.

I'm wondering why, and any inputs will be highly appreciated.

(venv3.7) [user@host freeze]$ pip install -I arrow==0.13.2
Collecting arrow==0.13.2
  Using cached arrow-0.13.2-py2.py3-none-any.whl (37 kB)
Collecting python-dateutil
  Using cached python_dateutil-2.8.1-py2.py3-none-any.whl (227 kB)
Collecting six>=1.5
  Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Installing collected packages: six, python-dateutil, arrow
Successfully installed arrow-0.17.0 python-dateutil-2.8.1 six-1.15.0
(venv3.7) [user@host freeze]$
2 Answers

Use --force-reinstall instead of -I, --ignore-installed.

-I can break existing installs, according to the docs:

-I, --ignore-installed Ignore the installed packages, overwriting them. This can break your system if the existing package is of a different version or was installed with a different package manager!

If you want to install a version older than what you currently have installed, --force-reinsall is a better fit:

--force-reinstall Reinstall all packages even if they are already up-to-date.

A demonstration of --force-reinstall in action:

$ pip install arrow==0.17.0
Collecting arrow==0.17.0
<... snip ...>
Successfully installed arrow-0.17.0

$ pip install --force-reinstall arrow==0.13.2
Collecting arrow==0.13.2
<... snip ...>
Attempting uninstall: arrow
Found existing installation: arrow 0.17.0
Uninstalling arrow-0.17.0:
  Successfully uninstalled arrow-0.17.0
Successfully installed arrow-0.13.2 python-dateutil-2.8.1 six-1.15.0

$ pip freeze | grep arrow
arrow==0.13.2

Another option from luasoftware.com

% pip install arrow  
Collecting arrow
  Downloading arrow-1.2.1-py3-none-any.whl (63 kB)
     |████████████████████████████████| 63 kB 110 kB/s            
Installing collected packages: six, python-dateutil, arrow
Successfully installed arrow-1.2.1

% pip install --upgrade arrow==0.13.2
Collecting arrow==0.13.2
  Downloading arrow-0.13.2-py2.py3-none-any.whl (37 kB)
    Installing collected packages: arrow
  Attempting uninstall: arrow
    Found existing installation: arrow 1.2.1
    Uninstalling arrow-1.2.1:
      Successfully uninstalled arrow-1.2.1
Successfully installed arrow-0.13.2
% pip list | grep arrow
arrow             0.13.2
Related