gpt4 book ai didi

python - 如何在 Python 中使用 psycopg2-binary?

转载 作者:行者123 更新时间:2023-12-05 06:21:31 29 4
gpt4 key购买 nike

我使用 pip install psycopg2-binary 安装了 psycopg2-binary 包。但是我什么时候可以在 Python 中使用它呢?

import psycopg2 as pg2
conn = pg2.connect(database = 'dvdrental', user = 'postgres', password = secret)
cur = conn.cursor()
cur.execure('select * from actor')
cur.fetchmany(5)

---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-c2276cd20949> in <module>()
----> 1 import psycopg2 as pg2
2 conn = pg2.connect(database = 'dvdrental', user = 'postgres', password = secret)
3 cur = conn.cursor()
4 cur.execure('select * from actor')
5 cur.fetchmany(5)
ModuleNotFoundError: No module named 'psycopg2'

最佳答案

我在 Mac 上使用 Django。这对我有用。

在我的虚拟环境中,我运行了:

pip install psycopg2-binary

settings.py 中我指定:

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',

数据库凭据已被关闭。我知道这不是 OP 所要求的,但希望它会对某人有所帮助。

关于python - 如何在 Python 中使用 psycopg2-binary?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59811370/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com