12

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
MD. Khairul Basar
  • 4,237
  • 11
  • 38
  • 52
Rakesh Kumar
  • 127
  • 1
  • 1
  • 5
  • 1
    Possible duplicate of [pip install fails for every package ("Could not find a version that satisfies the requirement")](https://stackoverflow.com/questions/49748063/pip-install-fails-for-every-package-could-not-find-a-version-that-satisfies-th) – phd Apr 13 '18 at 13:42

4 Answers4

35

Try this:

pip install psycopg2-binary
oneor0
  • 1,254
  • 13
  • 23
  • 5
    first `pip uninstall psycopg2 psycopg2-binary` Then `pip install psycopg2` . That way dependencies dont get messed up – Aseem Apr 02 '19 at 09:00
5

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;
print(requests.get('https://www.howsmyssl.com/a/check',verify=False).json()['tls_version'])"

Or Python 3:

python3 -m pip install --upgrade requests
python3 -c "import requests; 
print(requests.get('https://www.howsmyssl.com/a/check',verify=False).json()['tls_version'])"

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.

mdegis
  • 1,860
  • 2
  • 21
  • 30
0

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
>>> 
VynlJunkie
  • 1,338
  • 16
  • 21
0

*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: D:\Anaconda3\Library\bin

Resolution:

My workaround: I have copied the following files

libcrypto-1_1-x64.* libssl-1_1-x64.* from D:\Anaconda3\Library\bin to D:\Anaconda3\DLLs.

Arunph
  • 1
  • 3