title: Apple M1： install psycopg2 package Symbol not found: _PQbackendPID
body: <p><a href="https://i.stack.imgur.com/8RpiT.png" rel="noreferrer"><img src="https://i.stack.imgur.com/8RpiT.png" alt="enter image description here" /></a></p>
  <p>pg_config</p>
  <pre><code>venv ❯ which pg_config
  
  /Applications/Postgres.app/Contents/Versions/latest/bin/pg_config
  
  </code></pre>
  <pre><code>pip3 install -r requirements.txt
  </code></pre>
  <p>requirements.txt</p>
  <pre><code>venv ❯ cat requirements.txt
  -i https://mirrors.aliyun.com/pypi/simple/
  alembic==1.4.2
  amqp==2.6.0
  billiard==3.6.3.0
  celery==4.4.6
  certifi==2020.6.20
  chardet==3.0.4
  click==7.1.2
  emoji==0.5.4
  fastapi==0.59.0
  future==0.18.2
  h11==0.9.0
  httptools==0.1.1 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
  idna==2.10
  kombu==4.6.11
  mako==1.1.3
  markupsafe==1.1.1
  psycopg2-binary==2.8.5
  pydantic==1.6
  python-dateutil==2.8.1
  python-editor==1.0.4
  pytz==2020.1
  redis==3.5.3
  requests==2.24.0
  six==1.15.0
  sqlalchemy==1.3.18
  starlette==0.13.4
  tenacity==6.2.0
  urllib3==1.25.9
  uvicorn==0.11.5
  uvloop==0.14.0 ; sys_platform != 'win32' and sys_platform != 'cygwin' and platform_python_implementation != 'PyPy'
  vine==1.3.0
  websockets==8.1
  </code></pre>
  <p>full error message</p>
  <pre><code>Process SpawnProcess-1:
  Traceback (most recent call last):
    File &quot;/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py&quot;, line 315, in _bootstrap
      self.run()
    File &quot;/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/process.py&quot;, line 108, in run
      self._target(*self._args, **self._kwargs)
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/uvicorn/subprocess.py&quot;, line 62, in subprocess_started
      target(sockets=sockets)
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/uvicorn/main.py&quot;, line 382, in run
      loop.run_until_complete(self.serve(sockets=sockets))
    File &quot;uvloop/loop.pyx&quot;, line 1456, in uvloop.loop.Loop.run_until_complete
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/uvicorn/main.py&quot;, line 389, in serve
      config.load()
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/uvicorn/config.py&quot;, line 288, in load
      self.loaded_app = import_from_string(self.app)
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/uvicorn/importer.py&quot;, line 23, in import_from_string
      raise exc from None
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/uvicorn/importer.py&quot;, line 20, in import_from_string
      module = importlib.import_module(module_str)
    File &quot;/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/importlib/__init__.py&quot;, line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1014, in _gcd_import
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 991, in _find_and_load
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 975, in _find_and_load_unlocked
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 671, in _load_unlocked
    File &quot;&lt;frozen importlib._bootstrap_external&gt;&quot;, line 783, in exec_module
    File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 219, in _call_with_frames_removed
    File &quot;./main.py&quot;, line 4, in &lt;module&gt;
      from api.api_v1.api import api_router
    File &quot;./api/api_v1/api.py&quot;, line 4, in &lt;module&gt;
      from api.api_v1.endpoints import status
    File &quot;./api/api_v1/endpoints/status.py&quot;, line 10, in &lt;module&gt;
      from db.session import Session
    File &quot;./db/session.py&quot;, line 7, in &lt;module&gt;
      engine = create_engine(config.SQLALCHEMY_DATABASE_URI, pool_pre_ping=True)
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/sqlalchemy/engine/__init__.py&quot;, line 500, in create_engine
      return strategy.create(*args, **kwargs)
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py&quot;, line 87, in create
      dbapi = dialect_cls.dbapi(**dbapi_args)
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py&quot;, line 753, in dbapi
      import psycopg2
    File &quot;/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/psycopg2/__init__.py&quot;, line 51, in &lt;module&gt;
      from psycopg2._psycopg import (                     # noqa
  ImportError: dlopen(/Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so, 2): Symbol not found: _PQbackendPID
    Referenced from: /Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so
    Expected in: flat namespace
   in /Users/lidashuang/Projects/starservices/venv/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so
  </code></pre>