This post is a quick note to all about how to install psycopg2 in Linux. I used WSL 2 running Ubuntu 20.04.
I was trying to set up a toy project to learn Django using PostgreSQL. When I tried to install the recommend psycopg2 package from pip, I received two error messages.
The first error I received was: error: invalid command 'bdist_wheel' . My second error was related to C / C++ and was in my log files:
In file included from psycopg/adapter_asis.c:28:
./psycopg/psycopg.h:35:10: fatal error: Python.h: No such file or directory 35 | #include <Python.h> | ^~~~~~~~~~
- I installed the following dependencies:
- I installed wheels using
pip3 install wheel.
- I installed
python[your version]-devusing Ubuntu's
The root cause of the problem was that psycopg2 was looking for headers for Python 3.8.5. Since I am using Python 3.9.5, the headers could not be located and psycopg2 could not install. After installing
python3.9-dev , psycopg2 successfully installed on my system.
I hope that this short post saves people time and energy.