Best way to install psycopg2 on ubuntu 14.04

14,486

Solution 1

The psycopg you installed through apt-get is not visible from inside the virtual env.

You should install it through pip

pip install psycopg2

after sourcing your environment.

Solution 2

If you need psycopg2 for a system installed program, then install it with the system package manager. If you need it for a program in a virtualenv, install it in that virtualenv.

. env/bin/activate
pip install psycopg2

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 python and postgresql headers.

sudo apt-get install python-dev libpq-dev

psycopg 2.7 now issues a warning that it will stop providing binary releases due to compatibility issues.

The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.

See the release announcement for a thorough explanation. To handle the warning, tell pip not to download the pre-built wheel for psycopg2.

pip install --no-binary psycopg2 psycopg2

Solution 3

For me, to resolve this issue on Ubuntu 14.04 with virtualenv I had to

sudo apt-get install python3.5-dev

then I could run

pip install psycopg2
Share:
14,486
user3125823
Author by

user3125823

Updated on June 04, 2022

Comments

  • user3125823
    user3125823 over 1 year

    I am having trouble installing a Django app (Mezzanine) on Ubuntu 14.04. I've installed most necessities using apt-get (except for django-compressor and south -used pip), including psycopg2 for Postgres. However when I go to run python manage.py createdb it gives this error:

    Error loading psycopg2 module: No module named psycopg2
    

    This is the command I'm using to install psycopg2:

    sudo apt-get install python-psycopg2
    

    What am I doing wrong? Should I use pip to install psycopg2. I went to the website and it recommends installing through your OS package manager instead of pip.

    I am working in a virtualenv except for when I am installing the psycopg2 elements....