533
Use these following commands, this will solve the error:
sudo apt-get install postgresql
then fire:
sudo apt-get install python-psycopg2
and last:
sudo apt-get install libpq-dev
77
I just run this command as a root from terminal and problem is solved,
sudo apt-get install -y postgis postgresql-9.3-postgis-2.1
pip install psycopg2
or
sudo apt-get install libpq-dev python-dev
pip install psycopg2
- [Django]-*_set attributes on Django Models
- [Django]-How to check if a user is logged in (how to properly use user.is_authenticated)?
- [Django]-Django. A good tutorial for Class Based Views
- [Django]-How do you dynamically hide form fields in Django?
- [Django]-Django admin and MongoDB, possible at all?
- [Django]-How to combine django "prefetch_related" and "values" methods?
30
For me this simple command solved the problem:
sudo apt-get install postgresql postgresql-contrib libpq-dev python-dev
Then I can do:
pip install psycopg2
- [Django]-How to recursively query in django efficiently?
- [Django]-CORS error while consuming calling REST API with React
- [Django]-How do I get user IP address in Django?
20
For Python 3, I did:
sudo apt install python3-dev postgresql postgresql-contrib python3-psycopg2 libpq-dev
and then I was able to do:
pip3 install psycopg2
- [Django]-Best practices for adding .gitignore file for Python projects?
- [Django]-Django, Turbo Gears, Web2Py, which is better for what?
- [Django]-Why won't Django use IPython?
17
They changed the packaging for psycopg2. Installing the binary version fixed this issue for me. The above answers still hold up if you want to compile the binary yourself.
See http://initd.org/psycopg/docs/news.html#what-s-new-in-psycopg-2-8.
Binary packages no longer installed by default. The ‘psycopg2-binary’ package must be used explicitly.
And http://initd.org/psycopg/docs/install.html#binary-install-from-pypi
So if you don’t need to compile your own binary, use:
pip install psycopg2-binary
- [Django]-Django REST Framework (DRF): Set current user id as field value
- [Django]-Django Cannot set values on a ManyToManyField which specifies an intermediary model. Use Manager instead
- [Django]-Getting Values of QuerySet in Django
13
You must setup postgresql-server-dev-X.Y, where X.Y. your’s servers version, and it will install libpq-dev and other servers variables at modules for server side developing.
In my case it was
apt-get install postgresql-server-dev-9.5
Reading package lists… Done
Building dependency tree Reading state information… Done The
following packages were automatically installed and are no longer
required: libmysqlclient18 mysql-common Use ‘apt-get autoremove’ to
remove them. The following extra packages will be installed:
libpq-dev Suggested packages: postgresql-doc-10 The following NEW
packages will be installed: libpq-dev postgresql-server-dev-9.5
In your’s case
sudo apt-get install postgresql-server-dev-X.Y
sudo apt-get install python-psycopg2
- [Django]-Ignoring Django Migrations in pyproject.toml file for Black formatter
- [Django]-Django-Forms with json fields
- [Django]-Django.contrib.auth.logout in Django
5
I was using a virtual environment on Ubuntu 18.04, and since I only wanted to install it as a client, I only had to do:
sudo apt install libpq-dev
pip install psycopg2
And installed without problems. Of course, you can use the binary as other answers said, but I preferred this solution since it was stated in a requirements.txt file.
- [Django]-Table thumbnail_kvstore doesn't exist
- [Django]-DatabaseError: current transaction is aborted, commands ignored until end of transaction block?
- [Django]-Combining Django F, Value and a dict to annotate a queryset
3
Run the command below;
sudo apt-get install python-pip python-dev libpq-dev postgresql postgresql-contrib
pip install psycopg2
- [Django]-How to force Django models to be released from memory
- [Django]-Best practices for adding .gitignore file for Python projects?
- [Django]-Authenticate by IP address in Django
2
In my case, I was facing this problem when I ran pip install -r requirements.txt
to install all packages for a Django project with PostgreSQL database on an Ubuntu machine, I ran into this error and many other installation errors.
To solve this one, I ran the following commands:
sudo apt install postgresql postgresql-contrib
sudo apt install libpq-dev
sudo apt install python3-dev
sudo apt install python3-pip
sudo apt install python3-psycopg2
pip3 install psycopg2
pip3 install psycopg2-binary
Plus, also check if the Ubuntu and Python and Psycopg versions are compatible together.
Also, pip install aiopg
, solve the issue when i ran into it the second time.
- [Django]-How to add superuser in Django from fixture
- [Django]-TypeError: data.forEach is not a function
- [Django]-Remove pk field from django serialized objects