Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to install psycopg2 on ubuntu 14.04

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....

like image 925
user3125823 Avatar asked May 08 '15 15:05

user3125823


People also ask

Should I use psycopg2-binary?

The psycopg2-binary package is meant for beginners to start playing with Python and PostgreSQL without the need to meet the build requirements. If you are the maintainer of a published package depending on psycopg2 you shouldn't use psycopg2-binary as a module dependency.

Is psycopg2 the same as psycopg2-binary?

psycopg2-binary and psycopg2 both give us the same code that we interact with. The difference between the two is in how that code is installed in our computer.

What is import psycopg2 in Python?

Psycopg is the most popular PostgreSQL database adapter for the Python programming language. Its main features are the complete implementation of the Python DB API 2.0 specification and the thread safety (several threads can share the same connection).


1 Answers

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
like image 195
davidism Avatar answered Oct 02 '22 06:10

davidism