You are not logged in Log in Join
You are here: Home » Members » adytumsolutions » Documentation » PsycopgMacOSX » wikipage_view

Log in
Name

Password

 
 
FrontPage »

PsycopgMacOSX

Building psycopg-1.0.14 on Mac OS X

Introduction

psycopg is currently the very best Zope database adaptor for PostgreSQL?. Getting it running on production linux boxen was a simple task; it was a little more involved on Mac OS X.

Note: Please read this carefully! This is a document relaying a learning process; some of the steps mentioned are not to be followed. They are given as a shared education ;-)

UNIX Command Line - configuring and installing

The first problem I ran into while compiling psycopg was that the wrong CFLAGS and LDFLAGS were being set. From the psycopg README, I assume this is due to an problem with the way python is compiled on Mac OS X.

What I had to do to resolve this was edit the config file. Before all the gcc stuff, I added the following lines (at line 902 of the configure script):

 export LDFLAGS="-arch ppc" 
 export CFLAGS=""

I no longer received the error:

 checking whether the C compiler (gcc   -arch i386 -arch ppc ) works... no
 configure: error: installation or configuration problem: C compiler cannot create executables.

The next problem I encountered was the inability of the configure script to find the postgres libs and headers. I searched for the following files:

 libpq.so
 pg_type.h

and then added the paths to these files as parameters to the configure script:

 ./configure \
 --with-postgres-libraries=/usr/local/pgsql/lib \
 --with-postgres-includes=/Users/duncanmcgreggor/workbench/web_app_db/Bricolage/postgresql-7.3.1/src/include

The third problem I ran into was the mxDateTime.h headers missing. I knew I needed these, but being on the metro while compiling psycopg prevented me from downloading it ;-) After downloading and compiling mxDateTime, I had to do add the following to the script parameters:

 ./configure \
 --with-postgres-libraries=/usr/local/pgsql/lib \
 --with-postgres-includes=/Users/duncanmcgreggor/workbench/web_app_db/Bricolage/postgresql-7.3.1/src/include \
 --with-mxdatetime-includes=/usr/lib/python2.2//site-packages/mx/DateTime/mxDateTime 

This did not work, as configure returned errors of not being able to find other postgres include files. To rectify this, I copied some headers from the install source to the include dir and then re-ran configure:

 sudo cp -rp \
 /Users/duncanmcgreggor/workbench/web_app_db/Bricolage/postgresql-7.3.1/src/include/catalog \
 /usr/local/pgsql/include/

 ./configure \
 --with-postgres-libraries=/usr/local/pgsql/lib \
 --with-postgres-includes=/usr/local/pgsql/include \
 --with-mxdatetime-includes=/usr/lib/python2.2/site-packages/mx/DateTime/mxDateTime 

That worked, and then all I had to do was install the Product:

 sudo cp -rp ZPsycopgDA /Applications/Internet/Plone/PloneInstance/Products

However, starting up Zope resulted in errors complaining of the inability to find psycopg. Well, this was silly, since the python for Plone and the one on my system (in the regular path) have different lib dirs, etc.

I then copied the .so from one to the other:

 udo cp  \
 /usr/lib/python2.2/site-packages/psycopgmodule.so \
 /Applications/Internet/Plone/Python/lib/python2.1/lib-dynload

So, this should have worked, right? Wrong! My Plone instance on Mac OS X has its own python and libs different versions... so Zope just kept quiting and restarting itself.

To take care of this, I started over with a change to my $PATH:

 export PATH=/Applications/Internet/Plone/Python/bin:$PATH

I then rebuilt mxDateTime with the Plone python, installed it, and then ran the config:

 ./configure \
  --with-postgres-libraries=/usr/local/pgsql/lib \
  --with-postgres-includes=/usr/local/pgsql/include \
  --with-mxdatetime-includes=/Applications/Internet/Plone/Python/lib/python2.1/site-packages/mx/DateTime/mxDateTime 

However, the Makefile was still finding the system python, thus:

 rm /Applications/Internet/Plone/Python/lib/python2.1/lib-dynload

 rm config.cache

 ./configure \
  --with-postgres-libraries=/usr/local/pgsql/lib \
  --with-postgres-includes=/usr/local/pgsql/include \
  --with-mxdatetime-includes=/Applications/Internet/Plone/Python/lib/python2.1/site-packages/mx/DateTime/mxDateTime \
 --with-python=/Applications/Internet/Plone/Python/bin/python

 make && sudo make install

And that did it! Restart of Zope showed no looping crashes.

Using in Zope

Creation of postgres connection object was successful and a test of a ZSQL method returned correct results. Here's a brief outline of how I did these things:

  • Open up the ZMI, click on the plone site
  • In the main folder of the site, from the "Add" drop-down choose "Z Psycopg Database Connection"
  • The next screen that pops up, I used the following entries:
     id: pgzope
     title: Z Psycopg Database Connection
     connection string: dbname=zope user=zopeuser password=xxxxxxxx host=localhost port=5432
     connect immediately: checked
     use Zope's internal DateTime: checked
     PyGreSQL emulation: not checked
    
  • Click the "add" button, and you are connected!

Note: you will need to have first created a database in postgres as well as a user with a passname. You will then need to grant permissions for that user on the table you created.

Once your database connection is setup, you can test a ZSQL Method:

  • Create a table with data in postgres
  • Create a folder in Zope called sqlqueries
  • Enter that folder and then choose "Z SQL Method" from the "Add" drop-down
  • I gave my method the following entries:
     id: menus_main
     title: Main Menu
     connection id: choose the connection that you created above
     arguements: my query has no arguements, so I left this blank
     query template: SELECT name, link, display_order FROM menus WHERE menu_group = 'Main' ORDER BY display_order
    
  • Then hit "Add"
  • Then the ZMI will present you with the familiar management screen. When you select this item in the ZMI, you can use the test tab to see the output of your query.

I created a quick little template to show this data within the framework of my plone site:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html metal:use-macro="here/main_template/macros/master"
      i18n:domain="sqltest"
      xmlns="http://www.w3.org/1999/xhtml"
      xml:lang="en-US"
      lang="en-US">

 <head><title>Test Menus</title></head>
 <body>

 <div metal:fill-slot="main"
     tal:define="errors python:request.get('errors', {});      
     Iterator python:modules['Products.CMFPlone'].IndexIterator;
     tabindex python:Iterator(); 
     editor python:here.portal_membership.getAuthenticatedMember().wysiwyg_editor;
     wysiwyg python:test(editor and (editor!='None'), editor, 'None');">

   <h1>Our Menu</h1>

    <span tal:repeat="item here/sqlqueries/menus_main">

        <li/><a tal:attributes="href item/link"><span tal:content="item/name"/></a><br/>

    </span>

 </div>

 </body>
 </html>

When I "View"ed this file, or went to it directly, I got to see the magic of Zope + PostgreSQL? :-D Enjoy!