LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 01-29-2004, 01:31 PM   #1
iainr
Member
 
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'
python-base-2.3-3mdk
libmysql12-4.0.15-1mdk
MySQL-python2-0.9.2-1
postgresql-server-7.3.4-2mdk
libpython2.2-2.2.2-6mdk
MySQL-client-4.0.15-1mdk
libpython2.3-2.3-3mdk
python-2.3-3mdk
MySQL-4.0.15-1mdk
postgresql-7.3.4-2mdk
postgresql-python-7.3.4-2mdk
MySQL-common-4.0.15-1mdk
libpython2.3-devel-2.3-3mdk
postgresql-devel-7.3.4-2mdk

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
sourceforge.net/projects/mysql-python. 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/__init__.py:27: 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
"web").

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

Iain

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, 10:10 PM   #2
Manuel Tejada
Member
 
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 127.0.0.1 255.255.255.255 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, 03:50 PM   #3
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Original Poster
Rep: Reputation: 30
Manuel,

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


Reply


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 10:30 AM
PHP with MySQL and PostgreSQL ? Boby Linux - Software 2 05-25-2005 06:11 AM
MySQL,PostgreSQL and dbm. cranium2004 Linux - Software 1 03-10-2005 04:48 PM
PostgreSQL vs. MySQL mikeshn Programming 1 07-08-2002 01:23 PM
MySQL of PostgreSQL that is the question? Noerr Linux - Software 17 06-02-2002 04:07 PM


All times are GMT -5. The time now is 05:30 AM.

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