【发布时间】:2018-09-10 18:01:59
【问题描述】:
我试图将 sqlalchemy 与使用 timescaledb 扩展的底层 postgresql 连接起来。当我从 psql 终端客户端尝试时,所有查询都可以正常工作。但是当我尝试使用 python 和 sqlalchemy 来做这件事时,它一直给我一个错误。
这是我尝试使用的非常基本的代码 sn-p:
engine = create_engine('postgres://usr:pwd@localhost:5432/postgres', echo=True)
engine.execute('select 1;')
而且它总是显示以下错误信息:
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
与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()
这是完全相同的错误消息:
Connecting to database
Connected!
Traceback (most recent call last):
File "/home/usr/Workspace/somepath/web/model/model.py", line 21, in <module>
cursor.execute("\dx")
psycopg2.OperationalError: could not access file "timescaledb-0.9.0": No such file or directory
【问题讨论】:
-
可能需要最新版本的 Psycopg :initd.org/psycopg/docs/install.html
-
我使用 psycopg2 2.7.4 运行它,这是我相信的最新版本。 @RehanAzher
标签: python postgresql sqlalchemy timescaledb