我使用pip install opcopg2-binary安装了install copg2-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'发布于 2020-01-19 23:12:44
首先安装依赖项,
sudo apt-get install build-dep python-psycopg2在那之后
pip install psycopg2 发布于 2021-04-18 09:34:29
我在Mac上使用Django。这就是对我有效的方法。
在我的虚拟环境中,我运行:
pip install psycopg2-binary
在settings.py中,我指定:
数据库={‘默认’:{‘引擎’:‘django.db.backends.postgresql_default copg2’,
数据库凭据已停用。我知道这不是操作员所问的问题,但希望它能对某些人有所帮助。
发布于 2021-10-13 06:51:19
Debian Ubuntu/
pg_config通常由libpq-dev安装。
更多细节:https://www.psycopg.org/docs/install.html
Mac OS X
尝试使用macOS(或Linux) https://brew.sh/的Brew包管理器
brew install postgresql以及是否已安装Postgres.app
然后将路径更新为
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/14/bin可通过应用程序->Postgres.app->显示包内容->内容->版本->14检查版本
之后再做
pip install psycopg2 https://stackoverflow.com/questions/59811370
复制相似问题