88๐
Youโve installed the python-dev libraries for Python 3. Your psycopg2 install is using python 2.7
If on Ubuntu 20.04 or above
sudo apt-get install build-essential
Then run the other steps for either Python 2 or 3:
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 on Python 2
sudo apt update
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpq-dev
sudo apt-get install python-dev
sudo apt-get install python-pip
pip2 install psycopg2-binary
22๐
Note that on many distros, the development headers needed for compiling against libraries are not installed by default. For psycopg2 on Ubuntu youโll need the python3 and postgresql headers:
sudo apt install python3-dev libpq-dev
pip3 install psycopg2
These can be installed in your activated virtual environment.
- [Django]-Django database query: How to get object by id?
- [Django]-Django: How to get current user in admin forms?
- [Django]-You are trying to add a non-nullable field 'new_field' to userprofile without a default
18๐
I was testing my application on a ubuntu docker image that only has python2.7.6 installed (as happens in most big orgs)
If you are using python2.x (though you should plan to move to 3.x asap), check the below dependencies:
sudo apt update
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libpq-dev # this is required as psycopg2 uses pg_config
sudo apt-get install python-dev
sudo apt-get install python-pip
Now install psycopg2 using:
pip2 install psycopg2-binary
- [Django]-Python regex for integer?
- [Django]-Django, ImportError: cannot import name Celery, possible circular import?
- [Django]-Django: show/log ORM sql calls from python shell
16๐
I had the same error trying to install it in a virtualenv (with python3)
I solved it by installing a previous version of psycopg2.
pip install psycopg2==2.7.5
- [Django]-Django multiprocessing and database connections
- [Django]-Use Django ORM as standalone
- [Django]-How to write a unit test for a django view?
7๐
This solved mine. I am using Python 3.8.2, Ubuntu 20.04 LTS:
sudo apt-get install python3-dev
sudo apt-get install python3-pip
pip install psycopg2
- [Django]-Sending JSON using the django test client
- [Django]-Django FileField upload is not working for me
- [Django]-SyntaxError: Generator expression must be parenthesized
5๐
To install psycopg2
in ubuntu or mate 20 you need first to install:
sudo apt install libpq-dev
and then:
pip3 install psycopg2
- [Django]-Django DoesNotExist
- [Django]-Django connection to postgres by docker-compose
- [Django]-How can I detect Heroku's environment?
4๐
In my case, I was facing this problem when I ran pip install -r requirements.txt
to install all packages for a Django project 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, @Arghya Bhattacharya answers pip install aiopg
, solve the issue when i ran into it the second time.
- [Django]-Connect to a DB using psycopg2 without password
- [Django]-Http POST drops port in URL
- [Django]-Django template filters, tags, simple_tags, and inclusion_tags
1๐
I had to install this one as well on my Ubuntu 20.04 LTS:
sudo apt-get install build-essential
- [Django]-Django testing rest-framework: APIRequestFactory vs APIClient
- [Django]-What is the default order of a list returned from a Django filter call?
- [Django]-Uncaught TypeError: $(โฆ).datepicker is not a function(anonymous function)
1๐
I faced same issue on my ubuntu 18.04 LTS OS.
Also, face some issues in Pillow
. In both cases (psycopg2
and Pillow
) these command solved my issue.
sudo apt install -y build-essential libssl-dev libffi-dev python3-dev libjpeg-dev libjpeg8-dev
sudo apt install libpq-dev
sudo apt-get install python3-pip
Note: I have installed psycopg2
in python=3.8.5
environment.
- [Django]-Pylint "unresolved import" error in Visual Studio Code
- [Django]-'pip' is not recognized as an internal or external command
- [Django]-How to POST a django form with AJAX & jQuery
0๐
make sure you are using the correct psycopg version for the python version.
Example for python 3.8.
python 3.8, the supported version is psycopg 2.8.4.
Reference ubuntu 20.04 + python 3.8 , pip install psycopg2==2.7.3.2 error #1106
- [Django]-Django โ view sql query without publishing migrations
- [Django]-Django โ How to do tuple unpacking in a template 'for' loop
- [Django]-How can I check the size of a collection within a Django template?
-2๐
I solved this issue using another package which itself internally installs psycopg2.
pip install aiopg
- [Django]-What does error mean? : "Forbidden (Referer checking failed โ no Referer.):"
- [Django]-Model form save. Get the saved object
- [Django]-Get distinct values of Queryset by field