473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

MySQLDBAPI

Hey guys,

I'm trying to install the MySQLDB API at my web host. I only have
limited permissions on the system so I want to install it in my home
directory. I'm having a lot of trouble though.

My first question is if there is anything built into python as far as
a Database API that will work with MySQL. It seems like there should
be because Python without it is kinda useless for web development. If
there is then I'd probably prefer to use that instead.

My next question is, any idea why my install attempts below don't work?

Here's my system info:
print sys.version
2.4.1 (#1, Jun 6 2005, 13:31:05)
[GCC 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)]

Here are the steps I've taken trying to install it:

1. Download MySQL-python-1.2.0.tar.gz from project page into my home directory
http://sourceforge.net/projects/mysql-python

2. tar xvzf MySQL-python-1.2.0.tar.gz

3. Do these commands: cd MySQL-python-1.2.0
python2.4 setup.py install --home=~ running install
running build
running build_py
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.4 -c _mysql.c
-o build/temp.linux-i686-2.4/_mysql.o
-I'/usr/local/mysql/include/mysql'
_mysql.c:41:19: mysql.h: No such file or directory
_mysql.c:42:26: mysqld_error.h: No such file or directory
_mysql.c:43:20: errmsg.h: No such file or directory
error: command 'gcc' failed with exit status 1

4. I also tried running build: python2.4 setup.py build

running build
running build_py
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.4 -c _mysql.c
-o build/temp.linux-i686-2.4/_mysql.o
-I'/usr/local/mysql/include/mysql'
_mysql.c:41:19: mysql.h: No such file or directory
_mysql.c:42:26: mysqld_error.h: No such file or directory
_mysql.c:43:20: errmsg.h: No such file or directory
error: command 'gcc' failed with exit status 1

(I don't know if I need to run build first or what)

I found some help on http://docs.python.org/inst/inst.html
but I don't really understand what it's talking about.
I also read the README file in the download but it didn't help either.

Any ideas would be greatly appriciated.

Thanks,

Greg
Jul 19 '05 #1
11 1912
Gregory Piñero wrote:
Hey guys, (...)
My first question is if there is anything built into python as far as
a Database API that will work with MySQL. It seems like there should
be because Python without it is kinda useless for web development. If
there is then I'd probably prefer to use that instead.


there is not. mysqldb module is the answer.

(...)
cd MySQL-python-1.2.0
python2.4 setup.py install --home=~


running install
running build
running build_py
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.4 -c _mysql.c
-o build/temp.linux-i686-2.4/_mysql.o
-I'/usr/local/mysql/include/mysql'
_mysql.c:41:19: mysql.h: No such file or directory
_mysql.c:42:26: mysqld_error.h: No such file or directory
_mysql.c:43:20: errmsg.h: No such file or directory
error: command 'gcc' failed with exit status 1


you need mysql-devel package installed to compile the "_mysql" extension.

just look a the release notes:
<https://sourceforge.net/project/shownotes.php?group_id=22307&release_id=303257>

HTH.

--
deelan, #1 fan of adriana lima!
<http://www.deelan.com/>


Jul 19 '05 #2
I didn't see anything about mysql-devel package in the release notes.
Is that something I can install all to my home directory?

On 6/9/05, deelan <gg*@zzz.it> wrote:
Gregory Piñero wrote:
Hey guys,

(...)

My first question is if there is anything built into python as far as
a Database API that will work with MySQL. It seems like there should
be because Python without it is kinda useless for web development. If
there is then I'd probably prefer to use that instead.


there is not. mysqldb module is the answer.

(...)
cd MySQL-python-1.2.0
python2.4 setup.py install --home=~


running install
running build
running build_py
running build_ext
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.4 -c _mysql.c
-o build/temp.linux-i686-2.4/_mysql.o
-I'/usr/local/mysql/include/mysql'
_mysql.c:41:19: mysql.h: No such file or directory
_mysql.c:42:26: mysqld_error.h: No such file or directory
_mysql.c:43:20: errmsg.h: No such file or directory
error: command 'gcc' failed with exit status 1


you need mysql-devel package installed to compile the "_mysql" extension.

just look a the release notes:
<https://sourceforge.net/project/shownotes.php?group_id=22307&release_id=303257>

HTH.

--
deelan, #1 fan of adriana lima!
<http://www.deelan.com/>




--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #3
Gregory Piñero wrote:
I didn't see anything about mysql-devel package in the release notes.
it's there, section "Prerequisites".
Is that something I can install all to my home directory?


never tried, but sounds hard to do. mysql-devel is a bunch of libs and
include files tied to mysql. the "_mysql" extension will be complied
against such files and then wrapped by python code.

HTH.

--
deelan, #1 fan of adriana lima!
<http://www.deelan.com/>


Jul 19 '05 #4
Gregory Piñero wrote:
Is that something I can install all to my home directory?


If you have a similar Linux distribution at home, simply build the mysql
extension on that machine and then copy it to the web server.

Otherwise:

You don't have to actually install it. Just make sure that Setup.py
finds the headers and libs

1a) get the rpm and extract the files

or 1b) compile (but don't install) mysql from sources

2) specify the locations of the header files and the libs to Setup.py or
patch the module such that the defaults point to your directories. From
your error message, the current default for the includes seems to be
/usr/local/mysql/include/mysql

3) You can then delete the directories created in 1a or 1b

Daniel
Jul 19 '05 #5
see below

On 6/10/05, Daniel Dittmar <da************@sap.corp> wrote:
Gregory Piñero wrote:
Is that something I can install all to my home directory?
If you have a similar Linux distribution at home, simply build the mysql
extension on that machine and then copy it to the web server.


I have Ubuntu running at home and Redhat is running on the server.
Would this still work for me? Do I need to install the same old
version of MySql on my home computer?

Otherwise:

You don't have to actually install it. Just make sure that Setup.py
finds the headers and libs

1a) get the rpm and extract the files
Are you referring to the rpm for Mysql? I would just get the same
version as the server has?
or 1b) compile (but don't install) mysql from sources

2) specify the locations of the header files and the libs to Setup.py or
patch the module such that the defaults point to your directories. From
your error message, the current default for the includes seems to be
/usr/local/mysql/include/mysql
So the new location will be where I extracted the RPM to?

3) You can then delete the directories created in 1a or 1b
So the new python module, the dpapi will be installed in my home
directory? So when I import it from another script I would just
append my home directory to the sys.path first to use it?
Daniel
--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #6
While waiting for answers to the above questions, I went ahead and
tried the following:

1. Downloaded the RPM for the server's version of MySql:
http://downloads.mysql.com/archives/....57-1.i386.rpm

2. Copy file to server, and extract to a new folder i made called rpmmysql:
[gpinero@intel1 gpinero]$ cd rpmmysql/
[gpinero@intel1 rpmmysql]$ rpm2cpio
/home/gpinero/MySQL-devel-3.23.56-1.i386.rpm | cpio -d -i
3936 blocks
[gpinero@intel1 rpmmysql]$ ls
usr
[gpinero@intel1 rpmmysql]$ cd usr
[gpinero@intel1 usr]$ ls
bin include lib
[gpinero@intel1 usr]$ cd include/
[gpinero@intel1 include]$ ls
mysql
[gpinero@intel1 include]$ cd mysql
[gpinero@intel1 mysql]$ ls
chardefs.h m_ctype.h my_net.h mysql.h sslopt-case.h
dbug.h m_string.h my_no_pthread.h mysql_version.h sslopt-longopts.h
errmsg.h my_config.h my_pthread.h my_sys.h sslopt-usage.h
history.h my_global.h mysql_com.h raid.h sslopt-vars.h
keymaps.h my_list.h mysqld_error.h readline.h tilde.h
[gpinero@intel1 mysql]$

3. Edited setup.py to include the new directory. Here's my whole file
just in case you need it:

#!/usr/bin/env python

"""\
=========================
Python interface to MySQL
=========================

MySQLdb is an interface to the popular MySQL_ database server for
Python. The design goals are:

- Compliance with Python database API version 2.0 [PEP-0249]_

- Thread-safety

- Thread-friendliness (threads will not block each other)

MySQL-3.22 through 4.1 and Python-2.3 through 2.4 are currently
supported.

MySQLdb is `Free Software`_.

... _MySQL: http://www.mysql.com/
... _`Free Software`: http://www.gnu.org/
... [PEP-0249] http://www.python.org/peps/pep-0249.html

"""

import os
import sys
from distutils.core import setup
from distutils.extension import Extension

mysqlclient = os.getenv('mysqlclient', 'mysqlclient_r')
mysqlstatic = eval(os.getenv('mysqlstatic', 'False'))
embedded_server = (mysqlclient == 'mysqld')

name = "MySQL-%s" % os.path.basename(sys.executable)
if embedded_server:
name = name + "-embedded"
version = "1.2.1c3"

extra_objects = []

if sys.platform == "win32":
mysqlroot = os.getenv('mysqlroot', None)
if mysqlroot is None:
print "You need to set the environment variable mysqlroot!"
print "This should be the path to your MySQL installation."
print "Probably C:\Program Files\MySQL 4.1\ or something like that."
sys.exit(1)

include_dirs = [os.path.join(mysqlroot, "include")]
library_dirs = [os.path.join(mysqlroot, "libs")]
libraries = ['zlib', 'msvcrt', 'libcmt', 'wsock32', 'advapi32']
if mysqlstatic:
extra_objects.append(os.path.join(
library_dirs[0], mysqlclient+'.lib'))
else:
libraries.append(mysqlclient)

else:

def config(what):
from os import popen
f = popen("mysql_config --%s" % what)
data = f.read().strip().split()
if f.close(): data = []
return data

# This dequote() business is required for some older versions
# of mysql_config

def dequote(s):
if (s[0] == "'" or s[0] == '"') and (s[0] == s[-1]):
s = s[1:-1]
return s

include_dirs = [ dequote(i[2:]) for i in config('include') if
i.startswith('-i') ]
#include_dirs.append('/usr/local/mysql/include/mysql')
#include_dirs=['/usr/local/mysql/include/mysql']

if mysqlclient == "mysqlclient":
libs = config("libs")
elif mysqlclient == "mysqlclient_r":
libs = config("libs_r")
elif mysqlclient == "mysqld":
libs = config("embedded")
library_dirs = [ dequote(i[2:]) for i in libs if i.startswith("-L") ]
libraries = [ dequote(i[2:]) for i in libs if i.startswith("-l") ]

# Workaround for a pre-4.1.9 bug
if "z" not in libraries:
libraries.append("z")

extra_compile_args = config("cflags")

if mysqlstatic:
extra_objects.append(os.path.join(
library_dirs[0],'lib%s.a' % mysqlclient))
else:
libraries.append(mysqlclient)
classifiers = """
Development Status :: 5 - Production/Stable
Environment :: Other Environment
License :: OSI Approved :: GNU General Public License (GPL)
Operating System :: MacOS :: MacOS X
Operating System :: Microsoft :: Windows :: Windows NT/2000
Operating System :: OS Independent
Operating System :: POSIX
Operating System :: POSIX :: Linux
Operating System :: Unix
Programming Language :: C
Programming Language :: Python
Topic :: Database
Topic :: Database :: Database Engines/Servers
"""

metadata = {
'name': name,
'version': version,
'description': "Python interface to MySQL",
'long_description': __doc__,
'author': "Andy Dustman",
'author_email': "an**@dustman.net",
'license': "GPL",
'platforms': "ALL",
'url': "http://sourceforge.net/projects/mysql-python",
'download_url': "http://prdownloads.sourceforge.net/mysql-python/" \
"MySQL-python-%s.tar.gz" % version,
'classifiers': [ c for c in classifiers.split('\n') if c ],
'py_modules': [
"_mysql_exceptions",
"MySQLdb.converters",
"MySQLdb.connections",
"MySQLdb.cursors",
"MySQLdb.sets",
"MySQLdb.times",
"MySQLdb.stringtimes",
"MySQLdb.mxdatetimes",
"MySQLdb.pytimes",
"MySQLdb.constants.CR",
"MySQLdb.constants.FIELD_TYPE",
"MySQLdb.constants.ER",
"MySQLdb.constants.FLAG",
"MySQLdb.constants.REFRESH",
"MySQLdb.constants.CLIENT",
],
'ext_modules': [
Extension(
name='_mysql',
sources=['_mysql.c'],
include_dirs=include_dirs,
library_dirs=library_dirs,
libraries=libraries,
extra_compile_args=extra_compile_args,
extra_objects=extra_objects,
),
],
}
#include_dirs.append('/usr/local/mysql/include/mysql')
include_dirs.append('/home/gpinero/rpmmysql/usr/include/mysql')
setup(**metadata)
4. Tried building again:
[gpinero@intel1 MySQL-python-1.2.1c3]$ python2.4 setup.py build
running build
running build_py
running build_ext
building '_mysql' extension
gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -lz
-lmysqlclient_r -o build/lib.linux-i686-2.4/_mysql.so
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
Jul 19 '05 #7
Gregory Piñero wrote:
building '_mysql' extension
gcc -pthread -shared build/temp.linux-i686-2.4/_mysql.o -lz
-lmysqlclient_r -o build/lib.linux-i686-2.4/_mysql.so
/usr/bin/ld: cannot find -lmysqlclient_r
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1


Now search for mysqlclient_r.so or mysqlclient_r.a (probably in
rpmmysql/usr/lib.

A mysqlclient.so (without _r meaning without support for threading) will
do as well if you use Python as a CGI program.

Now enter the directory where you found mysqlclient to setup.py
library_dirs = ['<your dir>']

If you found both .so and .a, rm the .so. The linker will then link the
static library .a and you can copy the resulting _mysql.so everywhere.

If there is only an .so, be sure to copy the mysqlclient*.so to the
server together with _mysql.so. You probably have to inspect the
environment in your CGI run for LD_LIBRARY_PATH for a directory where
you can copy mysqlclient*.so. (That's why it is easier to use the static
library)

Daniel
Jul 19 '05 #8
The closest thing I found was libmysqlclient.a in
/home/gpinero/rpmmysql/usr/lib/mysql/

I added that path to my library_dir in setup.py but I still get the
same error message when I do python2.4 setup.py build

I really appriciate your help. I really want to start web development
in python.

Thanks,

Greg
Jul 19 '05 #9
Here's a list of all the files from the RPM extraction, maybe that helps too?
[gpinero@intel1 rpmmysql]$ dir -R
..:
usr

../usr:
bin include lib

../usr/bin:
comp_err mysql_config

../usr/include:
mysql

../usr/include/mysql:
chardefs.h m_ctype.h my_net.h mysql.h sslopt-case.h
dbug.h m_string.h my_no_pthread.h mysql_version.h sslopt-longopts.h
errmsg.h my_config.h my_pthread.h my_sys.h sslopt-usage.h
history.h my_global.h mysql_com.h raid.h sslopt-vars.h
keymaps.h my_list.h mysqld_error.h readline.h tilde.h

../usr/lib:
mysql

../usr/lib/mysql:
libdbug.a libmerge.a libmyisammrg.a libmystrings.a libnisam.a
libheap.a libmyisam.a libmysqlclient.a libmysys.a
Jul 19 '05 #10
One other note, the few searches I've made that seem somewhat relevant
talk about turning off something thread-safe? Is this something I can
try even though I have very limited permissions on the server?
On 6/14/05, Gregory Piñero <gr********@gmail.com> wrote:
Here's a list of all the files from the RPM extraction, maybe that helps too?


[gpinero@intel1 rpmmysql]$ dir -R
.:
usr

./usr:
bin include lib

./usr/bin:
comp_err mysql_config

./usr/include:
mysql

./usr/include/mysql:
chardefs.h m_ctype.h my_net.h mysql.h sslopt-case.h
dbug.h m_string.h my_no_pthread.h mysql_version.h sslopt-longopts.h
errmsg.h my_config.h my_pthread.h my_sys.h sslopt-usage.h
history.h my_global.h mysql_com.h raid.h sslopt-vars.h
keymaps.h my_list.h mysqld_error.h readline.h tilde.h

./usr/lib:
mysql

./usr/lib/mysql:
libdbug.a libmerge.a libmyisammrg.a libmystrings.a libnisam.a
libheap.a libmyisam.a libmysqlclient.a libmysys.a

Jul 19 '05 #11
Ok, I finally got it working! I just did these two commands:

$export mysqlclient=mysqlclient
$export mysqlstatic=True

Thanks for all the help everyone.

-Greg
On 6/14/05, Gregory Piñero <gr********@gmail.com> wrote:
One other note, the few searches I've made that seem somewhat relevant
talk about turning off something thread-safe? Is this something I can
try even though I have very limited permissions on the server?


On 6/14/05, Gregory Piñero <gr********@gmail.com > wrote:
Here's a list of all the files from the RPM extraction, maybe that helps too?
[gpinero@intel1 rpmmysql]$ dir -R
.:
usr

./usr:
bin include lib

./usr/bin:
comp_err mysql_config

./usr/include:
mysql

./usr/include/mysql:
chardefs.h m_ctype.h my_net.h mysql.h sslopt-case.h
dbug.h m_string.h my_no_pthread.h mysql_version.h sslopt-longopts.h
errmsg.h my_config.h my_pthread.h my_sys.h sslopt-usage..h
history.h my_global.h mysql_com.h raid.h sslopt-vars.h
keymaps.h my_list.h mysqld_error.h readline.h tilde.h

./usr/lib:
mysql

./usr/lib/mysql:
libdbug.a libmerge.a libmyisammrg.a libmystrings.a libnisam.a
libheap.a libmyisam.a libmysqlclient.a libmysys.a

Jul 19 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.