小编Yij*_*Tao的帖子

带有 timescaledb 扩展名的 postgresql 的 Sqlalchemy 设置

我试图将 sqlalchemy 与使用 timescaledb 扩展的底层 postgresql 连接起来。当我从 psql 终端客户端尝试它们时,所有查询都可以正常工作。但是当我尝试使用 python 和 sqlalchemy 来做这件事时,它一直给我一个错误。

这是我尝试使用的非常基本的代码片段:

engine = create_engine('postgres://usr:pwd@localhost:5432/postgres', echo=True)
engine.execute('select 1;')
Run Code Online (Sandbox Code Playgroud)

它总是显示以下错误消息:

File "/home/usr/.local/share/virtualenvs/redbird-lRSbFM0t/lib/python3.6/site-packages/psycopg2/extras.py", line 917, in get_oids
""" % typarray)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not access file "timescaledb-0.9.0": No such file or directory
Run Code Online (Sandbox Code Playgroud)

与db的连接很好,否则它不会知道db正在使用timescaledb。

任何人有任何见解?

更新:我尝试直接使用 psycopg2。它基本上给出了相同的错误。DB连接成功,但是无法访问timescaledb-0.9.0。

这是截取的代码

conn_string = "host='localhost' dbname='db' user='usr' password='pwd'"
print("Connecting to database\n ->%s " % (conn_string))

conn = psycopg2.connect(conn_string)
cursor = conn.cursor()
print("Connected!\n")

cursor.execute("\dx")
records = cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)

这是完全相同的错误消息:

Connecting to database
Connected!

Traceback (most recent …
Run Code Online (Sandbox Code Playgroud)

python postgresql sqlalchemy timescaledb

4
推荐指数
1
解决办法
5297
查看次数

标签 统计

postgresql ×1

python ×1

sqlalchemy ×1

timescaledb ×1