Questions tagged [psycopg2]

Psycopg is a PostgreSQL adapter for Python programming language. It implements PEP 249 with many extensions.

Psycopg is a PostgreSQL adapter for Python . It is a wrapper around the libpq library. Psycopg fully implements PEP 249. It is thread-safe. It supports asynchronous I/O, server-side cursors, COPY, large objects and two-phase commit. Psycopg is extensible with new adapters and typecasters.

Questions that relate directly to psycopg2 should receive this tag. If you are using a web framework, scientific library or ORM in conjunction with Psycopg2 be sure to include that information in your post, and consider adding tags for those libraries.

Psycopg can be easily installed on Linux or Mac, but lacks full support in Windows, though there is a port available. It requires some manual installation in a virtual environment.

Psycopg2 can be used to archive the state of objects, although it is often convenient to use an ORM (SQLAlchemy for example).

External Links

3471 questions
1005
votes
49 answers

pg_config executable not found

I am having trouble installing psycopg2. I get the following error when I try to pip install psycopg2: Error: pg_config executable not found. Please add the directory containing pg_config to the PATH or specify the full executable path with the…
user1448207
  • 10,185
  • 3
  • 11
  • 5
562
votes
33 answers

How to install psycopg2 with "pip" on Python?

I'm using virtualenv and I need to install "psycopg2". I have done the following: pip install http://pypi.python.org/packages/source/p/psycopg2/psycopg2-2.4.tar.gz#md5=24f4368e2cfdc1a2b03282ddda814160 And I have the following…
André
  • 21,421
  • 41
  • 110
  • 172
284
votes
20 answers

DatabaseError: current transaction is aborted, commands ignored until end of transaction block?

I got a lot of errors with the message : "DatabaseError: current transaction is aborted, commands ignored until end of transaction block" after changed from python-psycopg to python-psycopg2 as Django project's database engine. The code remains the…
jack
  • 15,121
  • 32
  • 94
  • 122
179
votes
15 answers

psycopg2: insert multiple rows with one query

I need to insert multiple rows with one query (number of rows is not constant), so I need to execute query like this one: INSERT INTO t (a, b) VALUES (1, 2), (3, 4), (5, 6); The only way I know is args = [(1,2), (3,4), (5,6)] args_str =…
Sergey Fedoseev
  • 2,270
  • 2
  • 16
  • 16
169
votes
10 answers

How do I get a list of column names from a psycopg2 cursor?

I would like a general way to generate column labels directly from the selected column names, and recall seeing that python's psycopg2 module supports this feature.
Setjmp
  • 23,834
  • 23
  • 67
  • 90
168
votes
3 answers

SQLAlchemy: engine, connection and session difference

I use SQLAlchemy and there are at least three entities: engine, session and connection, which have execute method, so if I e.g. want to select all records from table I can do this engine.execute(select([table])).fetchall() and…
ololobus
  • 2,459
  • 2
  • 16
  • 21
164
votes
23 answers

error installing psycopg2, library not found for -lssl

I run sudo pip install psycopg2 and I get a bunch of output that looks like: cc -DNDEBUG -g -fwrapv -Os ..... ..... cc -DNDEBUG -g -fwrapv -Os ..... ..... And at the end it says: ld: library not found for -lssl clang: error: linker command…
tscizzle
  • 7,911
  • 12
  • 48
  • 75
120
votes
3 answers

Python/postgres/psycopg2: getting ID of row just inserted

I'm using Python and psycopg2 to interface to postgres. When I insert a row... sql_string = "INSERT INTO hundred (name,name_slug,status) VALUES (" sql_string += hundred_name + ", '" + hundred_slug + "', " + status +…
AP257
  • 72,861
  • 84
  • 184
  • 258
110
votes
11 answers

How to set up a PostgreSQL database in Django

I'm new to Python and Django. I'm configuring a Django project using a PostgreSQL database engine backend, But I'm getting errors on each database operation. For example when I run manage.py syncdb, I'm getting: C:\xampp\htdocs\djangodir>python…
André
  • 21,421
  • 41
  • 110
  • 172
98
votes
15 answers

Mac + virtualenv + pip + postgresql = Error: pg_config executable not found

I was trying to install postgres for a tutorial, but pip gives me error: pip install psycopg A snip of error I get: Error: pg_config executable not found. Please add the directory containing pg_config to the PATH or specify the full executable…
KGo
  • 14,226
  • 8
  • 27
  • 44
93
votes
2 answers

psycopg2: AttributeError: 'module' object has no attribute 'extras'

In my code I use the DictCursor from psycopg2.extras like this dict_cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) However, all of the sudden I get the following error when I load the cursor: AttributeError: 'module' object has no…
n1000
  • 4,298
  • 3
  • 32
  • 57
92
votes
20 answers

Error: No module named psycopg2.extensions

I am trying to set up a PostgreSQL database for my django project, which I believe I have done now thanks to the replies to my last question Problems setting up a postgreSQL database for a django project. I am now trying to run the command 'python…
Jess
  • 1,389
  • 3
  • 13
  • 16
91
votes
2 answers

How do you get PyPy, Django and PostgreSQL to work together?

What fork, or combination of packages should one to use to make PyPy, Django and PostgreSQL play nice together? I know that PyPy and Django play nice together, but I am less certain about PyPy and PostgreSQL. I do see that Alex Gaynor has made a…
James R
  • 4,365
  • 3
  • 27
  • 40
91
votes
3 answers

Python/psycopg2 WHERE IN statement

What is the correct method to have the list (countryList) be available via %s in the SQL statement? # using psycopg2 countryList=['UK','France'] sql='SELECT * from countries WHERE country IN (%s)' data=[countryList] cur.execute(sql,data) As it is…
Matt
  • 6,364
  • 13
  • 49
  • 66
90
votes
16 answers

Can't install psycopg2 package through pip install... Is this because of Sierra?

I am working on a project for one of my lectures and I need to download the package psycopg2 in order to work with the postgresql database in use. Unfortunately, when I try to pip install psycopg2 the following error pops up: ld: library not found…
Jome
  • 1,075
  • 1
  • 9
  • 19
1
2 3
99 100