Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing psycopg2 fails completely. Huge error message (such as error: command 'gcc' failed with exit status 1)

I have a problem with installing psycopg2 on my mac. I tried several things such as installing it with pip and also homebrew. I also downloaded all dependencies but it still fails to install it.

I get the following error message, which looks horrifying:

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/1c/nhs40gy513143dfqyblmt3r80000gn/T/pip-install-rxlPem/psycopg2/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /private/var/folders/1c/nhs40gy513143dfqyblmt3r80000gn/T/pip-record-93LksX/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/1c/nhs40gy513143dfqyblmt3r80000gn/T/pip-install-rxlPem/psycopg2/

What could be the issue?

EDIT: Full error can be found here, and this appears to be the most relevant part:

clang: warning: no such sysroot directory: '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.sdk' [-Wmissing-sysroot]
In file included from psycopg/psycopgmodule.c:27:
In file included from ./psycopg/psycopg.h:34:
/Library/Frameworks/Python.framework/Versions/3.7/include/python3.7m/Python.h:25:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
like image 341
Al Nikolaj Avatar asked Sep 16 '25 05:09

Al Nikolaj


1 Answers

psycopg2 has some install dependencies that might be giving you trouble. In this case it looks like the install process can't find stdio.h, part of the C standard library. Installing the Xcode Command Line Tools might help.

But if you don't want to bother with this, try installing psycopg2-binary instead:

You can also obtain a stand-alone package, not requiring a compiler or external libraries, by installing the psycopg2-binary package from PyPI:

$ pip install psycopg2-binary

The binary package is a practical choice for development and testing but in production it is advised to use the package built from sources.

like image 119
Chris Avatar answered Sep 17 '25 20:09

Chris