Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to install psycopg2 on mac os

Tags:

python

macos

I am using python3.7.2 and pip 19.2.2 for a python application. The problem is that I can't install the dependency psycopg2 2.8.3 on MacOS.

Below is the error I got on running pip install psycopg2:

ld: library not found for -lssl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command 'clang' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for psycopg2

It seems that ssl is not installed so I tried to install pip install sssl but got this error:

ERROR: Command errored out with exit status 1:
     command: /Users/joey/.pyenv/versions/3.7.2/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/setup.py'"'"'; __file__='"'"'/private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/9c/fcm6pxnj39b1t777zpcfpbdh0000gn/T/pip-install-2ldzdiz0/ssl/setup.py", line 33
        print 'looking for', f
                          ^
    SyntaxError: Missing parentheses in call to 'print'. Did you mean print('looking for', f)?
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I don't understand why it failed. Is this because of a wrong version or relates to MacOS?

I have tried the method mentioned in this post: How to install psycopg2 with "pip" on Python?. I installed postgressql on the Mac and added /usr/local/Cellar/postgresql/11.5/bin/ on PATH env. But it doesn't help.

like image 708
Joey Yi Zhao Avatar asked Aug 22 '19 23:08

Joey Yi Zhao


People also ask

Does psycopg2 work with Python3?

The current psycopg2 implementation supports: Python 2 versions from 2.6 to 2.7. Python 3 versions from 3.2 to 3.6. PostgreSQL server versions from 7.4 to 9.6.

Is psycopg2 a package?

The psycopg2 package is the current mature implementation of the adapter: it is a C extension and as such it is only compatible with CPython.

How do I import psycopg2 into Anaconda?

Please add the directory containing pg_config to the PATH or specify the full executable path with the option: python setup.py build_ext --pg-config /path/to/pg_config build ... or with the pg_config option in 'setup. cfg'.


Video Answer


2 Answers

I think this thread may be of help error installing psycopg2, library not found for -lssl

clang is the default c compiler on osx, and is required for some python libraries to be built correctly. The ssl error is actually the clang linker complaining that there is no ssl library available to be used. The above thread should resolve your issue.

like image 66
Nate Dellinger Avatar answered Oct 11 '22 09:10

Nate Dellinger


I had the same issue, and looked at the thread posted by Nate, but found my solution here: How to update Xcode from command line, posted by Roy Huang, who referenced https://forums.developer.apple.com/thread/104296

It turns out Mojave and/or Xcode 10 does not create a /usr/include directory, which psycopg2 needs to be able to install.

like image 32
ProfX Avatar answered Oct 11 '22 11:10

ProfX