[Django]-Error trying to install Postgres for python (psycopg2)

186πŸ‘

βœ…

The python-dev package is required for compilation of Python extensions written in C or C++, like psycopg2. If you’re running a Debian-based distribution (e.g. Ubuntu), you can install python-dev by running

sudo apt install python-dev

or

sudo apt install python3-dev

depending on your python version (for example, sudo apt install python3.8-dev).

After that, proceed to install psycopg2 in your virtualenv environment as usual.

πŸ‘€lanzz

60πŸ‘

For Ubuntu 14.04, from Docker image python:3.4.3-slim this combination worked for me:

sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get install -y python3.4-dev
sudo apt-get install -y libpq-dev

pip3 install psycopg2

Note build-essential package. It was crucial in my case.

πŸ‘€neciu

15πŸ‘

I tried all the solution but only works be

pip install psycopg2-binary

after installing lib you can use import psycopg2 in python file and then further db connection config

πŸ‘€RaviPatidar

13πŸ‘

In my case (ubuntu 12.04 with python 2.7 and python 3.4 installed)

sudo apt-get install python3-dev 

was not enough. What did the trick was

sudo apt-get install python3.4-dev

6πŸ‘

On Amazon Linux within a python3 venv I had to do the following:

sudo yum install python3-devel postgresql-devel
pip install psycopg2
πŸ‘€Shawnzam

4πŸ‘

Debian:

sudo apt-get install gcc
πŸ‘€Paul Kenjora

4πŸ‘

For the latest Python 3.7 I had to install python3.7-dev:

sudo apt-get install -y python3.7-dev

πŸ‘€Nik

3πŸ‘

First of all install python-dev

sudo apt-get install python-dev

And to adecuate use try this:

This is to do with the encoding of your terminal not being set to UTF-8. Here is my terminal:

$ echo $LANG
es_UY.UTF-8
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
(qο½₯Ο‰ο½₯q)οΎ‰
>>> 

If I unset I got the same error you got:

$ unset LANG
$ python
Python 2.7.3 (default, Apr 20 2012, 22:39:59) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> s = '(\xef\xbd\xa1\xef\xbd\xa5\xcf\x89\xef\xbd\xa5\xef\xbd\xa1)\xef\xbe\x89'
>>> s1 = s.decode('utf-8')
>>> print s1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in position 1-5: ordinal not in range(128)
>>> 
πŸ‘€sandino

2πŸ‘

I’m using the Ubuntu distribution of Linux and did the following:

Install the latest version of the python3-dev library so C extensions work for python. The first command updates the package list in Ubuntu so the latest version of python3-dev is installed.

sudo apt-get update

sudo apt-get install python3-dev

Then I had to install the the missing development library for PostgreSQL: the "libpq-dev" package.

sudo apt-get install libpq-dev

After that, I was able to finish installing my dependencies.

πŸ‘€Matt Thurmond

1πŸ‘

sudo apt-get install -y build-essential after trying everything
with no success this helped me solve my problem.

0πŸ‘

In my case, I tried to install psysopg2 version 2.7.3.2 in a virtual environment with python3.8.

The above error occurred.

As it turned out, python3.8 requires psycopg2 version 2.8 or higher.

πŸ‘€foske

-1πŸ‘

Remove the current virtual environment and create another one. Install the dependencies first then the rest you’ve been using. This works

πŸ‘€malvern gondo

Leave a comment