How to downgrade numpy? How to downgrade numpy? numpy numpy

How to downgrade numpy?


You are likely confused between python2, python3, and different python virtual environments.

This is the most reliable source, in your case

$ python>>> import numpy>>> numpy.__version__'1.14.5'

To upgrade/downgrade numpy, you need to use pip that corresponds to the python that you are using. I think you are using python 2.7. Look around for a pip executable that corresponds to the installed package at /usr/local/lib/python2.7/dist-packages/pip.

This is not the "right" way, but it will work

python -m pip install numpy==x.y.z
  • python will just correspond to python interpreter you are using
  • -m pip will find the right pip that corresponds to your installation of python 2.7
  • numpy==x.y.z will force the downgrade

Now, you will probably run into permissions problems that will tempt you to use sudo. At that point, you can either try adding the --user flag ... but if you really have to use sudo, then consider creating a virtualenv. (Please.)

Probably The Right Thing to Do

Others have commented on this: maybe your indices are actually not integers.

(Related: Slice indices must be integers or None or have __index__ method)

Find the places in your code that is indexing into a list, and make sure that are actually integers.

assert isinstance(a, int), 'a must be an int'assert isinstance(b, int), 'b must be an int'x = y[a:b]

Keep adding those type assertions until you find the bug.


You can downgrade using the --upgrade flag it works both ways e.g

pip install --upgrade numpy==1.10.1


I doubt that you really do need, or want, to downgrade NumPy.

But that's not what your question is really about. You want to know why pip is showing one thing and python is showing another, and what you can do about that.


The reason you're seeing different things is that your pip doesn't go with your python.

When you run python, that's your Python 2.7, and packages you import there come from your 2.7 library, at /usr/local/lib/python2.7/.

When you run pip it's using your Python 3.4, and installing and looking for things in your Python 3.4's library, which is at /usr/local/lib/python3.4/.

So, pip show numpy is showing you the version of NumPy your Python 3.4 has, which is completely independent of the version of NumPy your Python 2.7 has.

If you didn't intend to use Python 2.7, the solution is to run Python 3.4 instead, usually just by using python3 instead of python.

If you did intend to use Python 2.7, the solution is to use the pip that goes with it. You may have a command named pip2 or pip2.7 for this, but the safest way is to use python -m pip instead of pip.


As a side note, given where your 3.4 NumPy is installed, it looks like you may have done something like apt-get python3-numpy or yum python-numpy or similar to install it, not pip install numpy. And probably something like apt-get python2-numpy to get the 2.7 version as well. If so, you may want to downgrade or upgrade it the same way you installed it in the first place, using your distro's package manager, instead of using pip. If not… then ignore this paragraph.


If this all seems way too complicated, but you really do need to have both Python 2.7 and Python 3.4 around, there are two things you should consider:

  • Always use virtual environments. Whenever possible, don't install anything globally; pick an environment to install it in. Whatever environment is active, python and pip will both be for that environment.
  • Install the latest version of Anaconda, with the latest version of Python (3.7 as of today), then ask it to install 3.4 and 2.7 conda environments. Use those environments, and never even touch your system 3.4 and 2.7.