0

I am using a MacOS and am trying to deploy my web app onto Heroku, but it keeps failing to build wheel for psycopg2. I have literally tried everything- I found this article useful: How to install psycopg2 with "pip" on Python?

But even after trying everything the wheel still fails to build.

Here is some of the error message if it helps:

psycopg/psycopgmodule.c: In function ‘psyco_is_main_interp’:
         psycopg/psycopgmodule.c:685:18: error: dereferencing pointer to incomplete type ‘PyInterpreterState’ {aka ‘struct _is’}
           685 |     while (interp->next)
               |                  ^~
         error: command '/usr/bin/gcc' failed with exit code 1
         ----------------------------------------
         ERROR: Failed building wheel for psycopg2
         Running setup.py clean for psycopg2
       Successfully built alembic blinker dominate Flask-Bootstrap Flask-Mail guess-language-spirit itsdangerous Mako python-editor visitor WTForms
       Failed to build psycopg2
       Installing collected packages: SQLAlchemy, MarkupSafe, Mako, python-editor, six, python-dateutil, alembic, pytz, Babel, blinker, certifi, chardet, click, dnspython, dominate, urllib3, elasticsearch, idna, email-validator, itsdangerous, Jinja2, Werkzeug, Flask, Flask-Babel, visitor, Flask-Bootstrap, Flask-Login, Flask-Mail, Flask-SQLAlchemy, Flask-Migrate, Flask-Moment, WTForms, Flask-WTF, guess-language-spirit, PyJWT, python-dotenv, requests, psycopg2, gunicorn
           Running setup.py install for psycopg2: started
           Running setup.py install for psycopg2: finished with status 'error'
           ERROR: Command errored out with exit status 1:
            command: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nqnkr57w/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nqnkr57w/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 /tmp/pip-record-u2t7aq2l/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.9/psycopg2
                cwd: /tmp/pip-install-nqnkr57w/psycopg2/

psycopg/psycopgmodule.c: In function ‘psyco_is_main_interp’:
           psycopg/psycopgmodule.c:685:18: error: dereferencing pointer to incomplete type ‘PyInterpreterState’ {aka ‘struct _is’}
             685 |     while (interp->next)
                 |                  ^~
           error: command '/usr/bin/gcc' failed with exit code 1
           ----------------------------------------
       ERROR: Command errored out with exit status 1: /app/.heroku/python/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-nqnkr57w/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-nqnkr57w/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 /tmp/pip-record-u2t7aq2l/install-record.txt --single-version-externally-managed --compile --install-headers /app/.heroku/python/include/python3.9/psycopg2 Check the logs for full command output.
  • What's your gcc version >> `/usr/bin/gcc -v` ? – Maurice Meyer Jul 11 '21 at 17:27
  • Hi Maurice, it is: Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.5 (clang-1205.0.22.9) Target: arm64-apple-darwin20.3.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin – Patrick Chong Jul 12 '21 at 07:49

1 Answers1

0

Maybe your platform does not meet the requirements to build it. You can alternatively install the standalone binary

pip install psycopg2-binary

You can read more about it here: docs

Jerven Clark
  • 1,191
  • 2
  • 13
  • 26
  • Thanks Jech, I had tried psycopg2-binary. I even uninstalled psycopg2 and only had psycopg2-binary but still have the same problem with the wheel failing to build. – Patrick Chong Jul 11 '21 at 07:31
  • Can I know what version of psycopg2 you're trying to install as well as your python version? I'm just bouncing ideas here but can you try it with latest version of psycopg2? – Jerven Clark Jul 11 '21 at 07:59
  • Of course, so psycopg2 and psycopg2-binary are both 2.9.1. (Now I only have the latter installed). My python version is 3.8.8. Do you think it can be a compatibility issue? – Patrick Chong Jul 11 '21 at 08:04
  • I can't say for sure but there are a lot of build issues for psycopg2 v2.7+python3.8 that's very similar to the one you described but that should be fixed in psycopg2 v2.9. Let me try to repro your issue on heroku. – Jerven Clark Jul 11 '21 at 08:24