Skip to content
Advertisement

How to prevent pip from replacing numpy+mkl with just numpy when installing packages that require numpy?

When I pip install (or pip install --upgrade) packages that require numpy, they have a tendency to uninstall my existing numpy+mkl (which has a high enough version to satisfy the numpy version requirement). Afterwards, they install numpy without +mkl, which causes problems for other packages that do require MKL. An example for which this happens is gym (which has 'numpy>=1.10.4' in its install_requires in setup.py).

I understand that this is related to the +mkl suffix that probably somehow messes with the versions, and understand I can fix it afterwards by downloading and installing numpy+mkl from https://www.lfd.uci.edu/~gohlke/pythonlibs/, but it gets annoying to manually do this every time over again when upgrading a package like gym to a new version. Is there any way to prevent numpy+mkl from getting uninstalled during the pip install --upgrade?


For me, this is happening on Windows 10, Python 3.6. I did not yet check if the same happens on Linux, but would be interested in an answer for that too if it’s different there.

My currently installed version of numpy+mkl (which often gets automatically uninstalled) is 1.13.3+mkl.

Advertisement

Answer

Using --upgrade-strategy, as suggested by cgohlke in a comment, addresses this problem. So, taking the example where we want to install gym from scratch without it replacing our existing numpy+mkl installation with regular numpy, the full command to run is:

pip install --upgrade-strategy only-if-needed gym

Or, if we just want to upgrade an existing installation, we also add --upgrade

pip install --upgrade --upgrade-strategy only-if-needed gym

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement