You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application
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
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.1pip install psycopg2
or
sudo apt-get install libpq-dev python-devpip install psycopg2