title: Psycopg2- wheel fails to build for MacOS
body: <p>I am using a MacOS and am trying to deploy my web app onto Heroku, but it keeps failing to <code>build wheel for psycopg2</code>. I have literally tried everything- I found this article useful: <a href="https://stackoverflow.com/questions/5420789/how-to-install-psycopg2-with-pip-on-python">How to install psycopg2 with &quot;pip&quot; on Python?</a></p>
  <p>But even after trying everything the wheel still fails to build.</p>
  <p>Here is some of the error message if it helps:</p>
  <pre><code>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-&gt;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] = '&quot;'&quot;'/tmp/pip-install-nqnkr57w/psycopg2/setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'/tmp/pip-install-nqnkr57w/psycopg2/setup.py'&quot;'&quot;';f=getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__);code=f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' 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-&gt;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] = '&quot;'&quot;'/tmp/pip-install-nqnkr57w/psycopg2/setup.py'&quot;'&quot;'; __file__='&quot;'&quot;'/tmp/pip-install-nqnkr57w/psycopg2/setup.py'&quot;'&quot;';f=getattr(tokenize, '&quot;'&quot;'open'&quot;'&quot;', open)(__file__);code=f.read().replace('&quot;'&quot;'\r\n'&quot;'&quot;', '&quot;'&quot;'\n'&quot;'&quot;');f.close();exec(compile(code, __file__, '&quot;'&quot;'exec'&quot;'&quot;'))' 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.
  </code></pre>