Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-29-2004, 12:31 PM   #1
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
Python with MySQL/PostgreSQL not working

I have been trying to get a connection between Python and a back-end database
: something that I expected to be a trivial exercise. Unfortunately, I seem
to be getting nowhere and could really do with some help.

My environment : Python 2.3 (#2, Aug 31 2003, 17:27:29)
[GCC 3.3.1 (Mandrake Linux 9.2 3.3.1-1mdk)] on linux2

RPMs installed :
-bash-2.05b$ rpm -qa|grep -iE 'python|mysql|postgres'

I don't think I have anything compiled from source or in other package formats
relevant to this.

1. MySQL

I have tried several versions of the MySQLdb module downloaded from The MySQL-python2-0.9.2-1 rpm got me
closest. I managed to get it installed (though had to ignore one dependency
where I had a newer version of the file it was depending on - always a bad
sign) and get the following message when importing the module

>>> import MySQLdb
/usr/lib/python2.3/site-packages/MySQLdb/ RuntimeWarning:
Python C API version mismatch for module _mysql: This Python has API version
1012, module _mysql has version 1011.
import _mysql

Other source versions, including the latest test version, fail to compile with
a host of errors.

2. PostgreSQL

I thought I would go for PostgreSQL next because the python module ships with
Mandrake. What could go wrong? The module (pg or _pg) loads up fine. I
still can't connect to the datbase though (I created a database called

>>> import _pg
>>> db = _pg.connect('web','localhost')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
_pg.error: could not connect to server: Connection refused
Is the server running on host localhost and accepting
TCP/IP connections on port 5432?

I checked and the database is running and is listening on port 5432.

Next I spotted something in the PostgreSQL manual, that I need to run the
createlang command first. I tried this but no luck :

-bash-2.05b$ createlang plpython web
ERROR: stat failed on file '$libdir/plpython': No such file or directory
createlang: language installation failed
-bash-2.05b$ createlang plpythonu web
createlang: unsupported language "plpythonu"
Supported languages are plpgsql, pltcl, pltclu, plperl, plperlu, and plpython.

I've hunted around and I can't find a plpython file anywhere on my PC so it
isn't installed. However, I also can't see any rpm than I'm missing.

Many thanks,


I posted this query to the tutor@python mailing list a week or so ago but unfortunately didn't get any good solutions
Old 02-02-2004, 09:10 PM   #2
Manuel Tejada
Registered: Jun 2002
Location: Lima, PERU
Distribution: Red Hat
Posts: 35

Rep: Reputation: 15
For PostgreSQL

Edit the postgrsql.conf file ( Is in Data directory):
Change the line #tcpip_socket = false, to
tcpip_socket = true

Edit the pg_hba.conf file ( In Data directory too):

Delete # simbol from line
#host all all trust

Be sure that the python modules you downloaded are for the version of the Python interpreter you have.

For MySQL really I don't know what to say.
Old 02-03-2004, 02:50 PM   #3
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Original Poster
Rep: Reputation: 30

Thank you. Your solution seems to have worked. As I only need one database to work, I'm happy now.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL x PostgreSQL Thakowbbery Linux - Enterprise 5 09-06-2005 09:30 AM
PHP with MySQL and PostgreSQL ? Boby Linux - Software 2 05-25-2005 05:11 AM
MySQL,PostgreSQL and dbm. cranium2004 Linux - Software 1 03-10-2005 03:48 PM
PostgreSQL vs. MySQL mikeshn Programming 1 07-08-2002 12:23 PM
MySQL of PostgreSQL that is the question? Noerr Linux - Software 17 06-02-2002 03:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:52 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration