Fix the pip error: Couldn't find a version that satisfies the requirement

Sometimes you get an error when you're trying to install a Python package using pip. It looks like this:

Could not find a version that satisfies the requirement (from versions:) No matching distribution found for

Some probable reasons for this error are:

  1. PyPI server isn't responding to your requests. It can happen either because the PyPI server is down or because it has blacklisted your IP address. This happened to me once when I was trying installing packages on a server. This can be fixed by using a proxy with pip. See the solution below.

  2. You're running an older pip (especially on Mac). This can be fixed by upgrading your pip. See this post on Stack Overflow.
    Thanks to Anupam Jain who pointed this in a comment.

  3. The package you're trying to install is not available for your Python version.

  4. The package is not available for your operating system. This is a rare case and only happens when the package is not pure-Python, i.e. it's been partially written in C or Cython. Such a package needs to be compiled for every operating system (Windows/Mac/Linux) and architecture (32-bit/64-bit). Suppose a package has only been compiled for Windows 64-bit, then you'll get this error if you try to install it on Windows 32-bit, or any other OS.

  5. The package is not present on PyPI server. In this case pip will not work. So you'll have to download and install the package manually from Github or wherever it is available.

Solution

I had this issue because PyPI server had blacklisted the IP of my hosting provider, the obvious solution was to make pip install via a proxy.

But to see if that's also the case with you, you can test it like this:

$ curl https://pypi.org

The requestors Network has been blacklisted due to excessive request volume. 
If you are a hosting customer, please contact your hosting company's support. 
If you are the hosting company, please contact infrastructure-staff@python.org to resolve

If you see the message similar to above, that means your IP has also been blacklisted by https://pypi.org.

If you don't see this message then the reason for the pip error could be that you're using an older version. See this post on Stack Overflow for a solution.

Anyways, this can be fixed by using a proxy with pip.

Supplying a proxy address to pip is easy:

$ pip install -r requirements.txt --proxy address:port

Above, address and port are IP address and port of the proxy.

To find proxies, just search Google for proxy list.

Other things that I tried

These are some other things that I tried to get rid of this issue. Although they didn't work for me, but they might work for you.

  1. Changing DNS resolver of my server.
    This makes sense if your server's DNS resolver can't find PyPI servers.
  2. Reconfiguring SSL, reinstalling CA certificates.
    This makes sense if you don't have updated CA certificates which are used by PyPI servers.
  3. Downloading packages using wget.
    This is an alternative way to install Python packages. Download them via wget and then install them using python setup.py install. In my case, the server was blacklisted by PyPI so I was getting a 403 Forbidden error.
  4. Downloading packages using curl.
    Alternative to wget. In my case I didn't get a 403 error but rather it just created invalid tarball files, instead of actually downloading them.
  5. Downloading packages using git or hg. If your desired packages have git or hg repositories that you can clone, this is a good workaround.