Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Got Django and Buildout working, but what about PIL and Postgres?

I'm on Mac OSX 10.5.8. I have followed Jacob Kaplan-Moss's article on setting up Django with Buildout: http://jacobian.org/writing/django-apps-with-buildout/

Finally, I have got this Buildout to work! ...but I'm now needing PIL and Postgres for a complete isolated Django development area. I've tried to modify my buildout.cfg with tutorials I've read around the internet, but just can't find how to do it without it throwing up all sorts of errors. I feel PIL and Postgres are the next things to complete this little setup, so I can just get on with it... (I'm not an expert at any of this by the way, I come from a PHP background). My current buildout.cfg looks like this:

[buildout]
parts = python django
develop = .
eggs = myproject

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[django]
recipe = djangorecipe
version = 1.1.1
project = myproject
projectegg = myproject
settings = testsettings
test = myproject
eggs = ${buildout:eggs}

Can anyone help me to reliably get PIL and Postgres working with my Buildout? Thank you so much in advance... Everything I've tried so far just throws up all sorts of errors.

like image 447
littlejim84 Avatar asked Jan 06 '10 15:01

littlejim84


People also ask

Does Django support PostgreSQL?

Django officially supports the following databases: PostgreSQL.

Why PostgreSQL is good with Django?

Benefits of using PostgreSQL with DjangoDjango has django. contrib. postgres to make database operations on PostgreSQL. If you are building an application with maps or you are storing geographical data, you need to use PostgreSQL, as GeoDjango is only fully compatible with PostgreSQL.


1 Answers

In theory, you should just be able to add PIL and psycopg2 to your eggs directive:

eggs = myproject
       PIL
       psycopg2

This works on some systems and in some situations.

However, there are two problems that can prevent it from working everywhere, and especially on OSX:

  1. PIL's packaging is... weird in some way, and that can make installing it from PyPI fail.
  2. Both PIL and psycopg2 are C extensions, which means you'll need to have the correct shared libraries and header files before you can build and install them.

Fixing (1) is easy: just add

find-links = http://dist.plone.org/thirdparty/

To your [buildout] section. The Plone folks maintain an egg-ified PIL that Just Works™ with Buildout.

Fixing (2) is a bit more complicated and situation-depdendant: you'll need to make sure you've got all the various header files that PIL and psycopg2 depend on.

psycopg2

If you've installed PostgreSQL from the PostgeSQL for Mac distribution (which I recommend), then it should have correctly installed the header files for you and psycopg2 will build okay.

If you've installed PostgreSQL from source, then you'll have the header files already; psycopg2 should build easily.

If, however, you've installed PostgreSQL some other way -- fink, ports, homebrew -- then you'll need to be careful and make sure you've got the development files install. In some package systems there's a separate postgresql-dev package with the development headers; others install those automatically.

If you've done this correctly, you should be able to run pg_config and verify that the INCLUDEDIR setting is set and correctly points to the header files (look for a libpq directory in the INCLUDEDIR directory).

PIL

PIL's a lot more tricky because it depends on a lot more libraries. At the very least you'll need to install libjpeg and libpng. If you're on 10.6 they should already be installed for you; if not, the easiest thing is probably to download and install them from source: libpng, libjpeg.

like image 176
jacobian Avatar answered Oct 08 '22 18:10

jacobian