sqlalchemy,尝试连接到本地数据库

问题描述

我有点知道,所以我不知道如何找到解决此类错误方法。正在尝试连接到本地数据库

from sqlalchemy import create_engine

rds_connection_string = "postgres:password@localhost:5432/ETL_DATABASES"
engine = create_engine(f'postgresql://{rds_connection_string}')

并得到:

--------------------------------------------------------------------------- ImportError                               Traceback (most recent call last) <ipython-input-12-db09b1b74d73> in <module>
      1 rds_connection_string = "postgres:password@localhost:5432/ETL_DATABASES"
----> 2 engine = create_engine(f'postgresql://{rds_connection_string}')
/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/__init__.py in create_engine(*args,**kwargs)
    498     strategy = kwargs.pop("strategy",default_strategy)
    499     strategy = strategies.strategies[strategy]
--> 500     return strategy.create(*args,**kwargs)
    501 
    502 
/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/engine/strategies.py in create(self,name_or_url,**kwargs)
     85                 if k in kwargs:
     86                     dbapi_args[k] = pop_kwarg(k)
---> 87             dbapi = dialect_cls.dbapi(**dbapi_args)
     88 
     89         dialect_args["dbapi"] = dbapi
/opt/anaconda3/lib/python3.8/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py in dbapi(cls)
    776     @classmethod
    777     def dbapi(cls):
--> 778         import psycopg2
    779 
    780         return psycopg2
/opt/anaconda3/lib/python3.8/site-packages/psycopg2/__init__.py in <module>
     49 # Import the DBAPI-2.0 stuff into top-level module.
     50 
---> 51 from psycopg2._psycopg import (                     # noqa
     52     BINARY,NUMBER,STRING,DATETIME,ROWID,53 
ImportError: dlopen(/opt/anaconda3/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so,2): Symbol not found: _PQencryptPasswordConn   
Referenced from: /opt/anaconda3/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so 
Expected in: /usr/lib/libpq.5.6.dylib  in /opt/anaconda3/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so

我在 jupyter notebook 中,并且在 sql 部分使用 pg Admin 4

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)