Search Postgresql Archives

plpythonu under OS X 10.4 -- a brief HOWTO

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,
I just got plpythonu working under OS X, and I'm posting my HOWTO notes here in case I (or anyone else) needs them.

The install was pretty straightforward for me once I'd Googled the proper magic commands. I'm on OS X Tiger (10.4.10) which comes with Python 2.3 installed by default. I wanted to have Python 2.5 available, so my first step was to download and build that. One must build Python with the "--enabled-shared" flag in order to be able to use plpythonu, and I don't know if the stock OS X install of Python has that flag. So even if you're satisfied with the stock Python install version, you might need to build a new version anyway.

Here's how I made Python:

export MACOSX_DEPLOYMENT_TARGET=10.4
./configure --enable-shared --enable-framework
make
sudo make frameworkinstall

That installed into /Library/Frameworks/Python.framework/Versions/ 2.5. (Note that OS X's python lives in /System/Library/Frameworks/ Python.framework/Versions/2.3, so the 2.5 install lives alongside of the system install rather than replacing it. This is good -- OS X uses Python and you don't want to monkey around with something on which OS X relies.) The installer helpfully symlinked /usr/local/bin/ python to /Library/Frameworks/Python.framework/Versions/2.5/bin/ python, so putting /usr/local/bin in my path before /usr/bin ensures that I invoke Python 2.5 automatically.

After that, I rebuilt postgres (I'm using 8.1.4 and building from / usr/local/src) with the following commands. I don't know if the "-- with-includes" and "--with-libraries" options are necessary for plpythonu, but I needed them to get readline support in psql. The 'make clean' step was necessary for me to resolve a linker error.

./configure --with-includes=/usr/local/include --with-libraries=/usr/ local/lib --with-python --enable-nls='en'
sudo make clean
sudo make install

I didn't back up my data or config files before reinstalling and do not appear to have lost anything. YMMV.

You should now have plpythonu available as a language in Postgres. In order to make it available in database my_stuff, start psql as superuser and execute these commands:

\c my_stuff

CREATE LANGUAGE plpythonu;

Since plpythonu is an untrusted language (that's what the 'u' on the end stands for), only superusers can create functions in that language. So as superuser you can create a function like so:

CREATE OR REPLACE FUNCTION show_python_version() RETURNS TEXT AS $$
    import sys

    return sys.version
$$ LANGUAGE plpythonu;

Then invoke psql as a normal user and try out your function:
> select * from show_python_version();
            show_python_version
--------------------------------------------
2.5.1 (r251:54863, Nov 17 2007, 21:19:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)]
(1 row)


That's all! Enjoy

Philip Semanchuk
first name @ last name.com


---------------------------(end of broadcast)---------------------------
TIP 3: Have you checked our extensive FAQ?

              http://www.postgresql.org/docs/faq

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux