Can't import from psycopg2 on Mac M1 Monterey 12.3.1

Viewed 89

After installing psycopg2-binary==2.9.1 via pip install -r requirements.txt, when I run python manage.py runserver command locally in a django project I get the following output and error:

    main()
  File "/Users/gabrielnaughton/development/tamato/manage.py", line 25, in main
    execute_from_command_line(sys.argv)
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/core/management/base.py", line 343, in run_from_argv
    connections.close_all()
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/db/utils.py", line 232, in close_all
    for alias in self:
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/db/utils.py", line 226, in __iter__
    return iter(self.databases)
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/utils/functional.py", line 48, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/db/utils.py", line 153, in databases
    self._databases = settings.DATABASES
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
    self._setup(name)
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
    self._wrapped = Settings(settings_module)
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
    mod = importlib.import_module(self.SETTINGS_MODULE)
  File "/opt/homebrew/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/Users/gabrielnaughton/development/tamato/settings/__init__.py", line 1, in <module>
    from settings.common import *
  File "/Users/gabrielnaughton/development/tamato/settings/common.py", line 16, in <module>
    from common.util import is_truthy
  File "/Users/gabrielnaughton/development/tamato/common/util.py", line 38, in <module>
    from psycopg2.extras import DateRange
  File "/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so, 0x0002): tried: '/Users/gabrielnaughton/development/tamato/venv/lib/python3.9/site-packages/psycopg2/_psycopg.cpython-39-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e'))

I have already seen this question and the top rated answer doesn't work for me. Any other ideas gratefully received.

0 Answers
Related