I’m using MAC and python version 2.7.14

Collecting psycopg2
  Could not fetch URL https://pypi.python.org/simple/psycopg2/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping
  Could not find a version that satisfies the requirement psycopg2 (from versions: )
No matching distribution found for psycopg2

Try this:

pip install psycopg2-binary

I had the same issue when I tried ‘pip installing’ packages for an ongoing project on a brand new MacBook running on Big Sur OS.
After some research, I came across this solution which worked for me.
Here are the steps:

  1. Install Homebrew using this command:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

  2. brew install postgresql

  3. brew install openssl

  4. brew link openssl

  5. Set the following environment variables (“flags”):

export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib"

export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"

  1. And finally install psycopg2 using the following command:

pip install psycopg2-binary

Here is the result:

Collecting psycopg2-binary
Using cached psycopg2-binary-2.9.1.tar.gz (380 kB)
Building wheels for collected packages: psycopg2-binary
Building wheel for psycopg2-binary (setup.py) … done
Created wheel for psycopg2-binary: filename=psycopg2_binary-2.9.1-cp39-cp39-macosx_10_9_universal2.whl size=241235 sha256=e825a38765f20a331ef619e1368ee9d1a678f34969e3c467d94bc4122af1ac6f
Stored in directory: /Users/me/Library/Caches/pip/wheels/4b/c8/c2/72089ea1a611c119754d513bdacea935cfeb19600d06d45b4b
Successfully built psycopg2-binary
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.9.1

Same issue, forgot to install psql:

So i ran:

brew install postgresql
brew services start postgresql

You’re using an older Python without the most secure TLS implementation, you need to upgrade it. Otherwise, you will not be able to “pip install” packages from PyPI.

1) To check your Python interpreter’s TLS version, install the “requests” package and run a command. For example, for Python 2:

python2 -m pip install --upgrade requests
python2 -c "import requests;

Or Python 3:

python3 -m pip install --upgrade requests
python3 -c "import requests; 

If you see “TLS 1.2”, your interpreter’s TLS is up to date. If you see “TLS 1.0” or an error like “tlsv1 alert protocol version”, then you must upgrade.

2) The reason Python’s TLS implementation is falling behind on macOS is that Python continues to use OpenSSL, which Apple has stopped updating on macOS. In the coming year, the Python Packaging Authority team will investigate porting pip to Apple’s own “SecureTransport” library as an alternative to OpenSSL, which would allow old Python interpreters to use modern TLS with pip only. “This is a non-trivial amount of effort,” writes Stufft, “I’m not sure it’s going to get done.”

In the long run, the Python interpreter itself would easily keep up with TLS versions, if it didn’t use OpenSSL on platforms like macOS and Windows where OpenSSL is not shipped with the OS. Cory Benfield and Christian Heimes propose to redesign the standard library’s TLS interfaces to make it easier to swap OpenSSL with platform-native TLS implementations.

I have faced a similar issue in the docker setup. I used the below package instead of psycopg2

pip install psycopg2-binary

This is and old question, but for what it may be worth.

If you are using the Conda packet management system simply run this on a terminal:

conda install psycopg2

I had this issue, asked and answered succesfully here:

Cannot get psycopg2 to work, but installed correctly. Mac OS

[save you a click]

I have installed anaconda2. The install updated my path to include /anaconda/bin.

Then using the navigator I installed pyscopg2. Now I am able to use this in the shebang and my scripts execute fine and i’m able to import this module.

Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul  2 2016, 17:43:17) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname="postgres" user="postgres" host="localhost""):
...     print "connection made"
connection made

A portable solution to solve this error regardless of the OpenSSL version for Mac users using homebrew

OPENSSL_VERSION=$(brew info openssl --json | jq '.[0].name')

export CPPFLAGS="-I/opt/homebrew/opt/$OPENSSL_VERSION/include"
export LDFLAGS="-L/opt/homebrew/opt/$OPENSSL_VERSION/lib"

pip install psycopg2 # OR psycopg2-binary

*I did a trace with Process Monitor.
D:\Anaconda3\DLLs_ssl.pyd search for the OpenSSL DLLs but in the wrong/current location!
As they are not found the search goes to C:\Windows\System32 where we have the same DLLs, installed by an other application, but with a different version.

The DLLs delivered by Anaconda3 are located here:


My workaround:
I have copied the following files

from D:\Anaconda3\Library\bin to D:\Anaconda3\DLLs.