Cannot install psycopg2 Ubuntu

You’ve installed the python-dev libraries for Python 3. Your psycopg2 install is using python 2.7 If you want to use Python 3: Make sure you’ve installed python3-pip sudo apt-get install python3-pip Then: pip3 install psycopg2 If that still fails, try installing the development headers for postgresql: sudo apt install python3-dev libpq-dev pip3 install psycopg2 If … Read more

ImportError: No module named ‘psycopg2._psycopg’

Eureka! I pulled my hair out for 2 days trying to get this to work. Enlightenment came from this SO Question. Simply stated, you probably installed psycopg2 x64 version like I did, not realizing your python version was 32-bit. Unistall your current psycopg2, then: Download: psycopg2-2.6.1.win32-py3.4-pg9.4.4-release.exe from HERE, then run the following in a Terminal: … Read more

How to mock psycopg2 cursor object?

You have a series of chained calls, each returning a new object. If you mock just the psycopg2.connect() call, you can follow that chain of calls (each producing mock objects) via .return_value attributes, which reference the returned mock for such calls: @mock.patch(“psycopg2.connect”) def test_super_awesome_stuff(self, mock_connect): expected = [[‘fake’, ‘row’, 1], [‘fake’, ‘row’, 2]] mock_con = … Read more

Use binary COPY table FROM with psycopg2

Here is the binary equivalent of COPY FROM for Python 3: from io import BytesIO from struct import pack import psycopg2 # Two rows of data; “id” is not in the upstream data source # Columns: node, ts, val1, val2 data = [(23253, 342, -15.336734, 2494627.949375), (23256, 348, 43.23524, 2494827.949375)] conn = psycopg2.connect(“dbname=mydb user=postgres”) curs … Read more

Django setting : psycopg2.OperationalError: FATAL: Peer authentication failed for user “indivo”

I have similar problem and solved it with this answer by adding localhost to the database HOST settings in settings.py, so your database settings should look like this: DATABASES = { ‘default’:{ ‘ENGINE’:’django.db.backends.postgresql_psycopg2′, # ‘.postgresql_psycopg2’, ‘.mysql’, or ‘.oracle’ ‘NAME’:’indivo’, # Required to be non-empty string ‘USER’:’indivo’, # Required to be non-empty string ‘PASSWORD’:’ritvik’, ‘HOST’:’localhost’, # … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)