[Pythonmac-SIG] building mysqldb on mac os x server

Dustin Lee ujeni at imt.net
Fri Aug 13 05:27:33 CEST 2004


Hi, I've seen a few messages about getting mysqldb built and installed 
but some how I can't get things working for me.  I'm trying to install 
MySQLdb 1.0.0.  
MacOSx version: (uname -a )
Darwin ???.???.???.??? 7.5.0 Darwin Kernel Version 7.5.0: Thu Aug  5 19:26
:16 PDT 2004; root:xnu/xnu-517.7.21.obj~3/RELEASE_PPC  Power Macintosh 
powerpc

 From setup.py I'm confused about this section:

elif sys.platform[:6] == "darwin": # Mac OS X
   include_dirs.append('/sw/include/mysql')
   library_dirs.append('/sw/lib/mysql')
   extra_link_args.append('-flat_namespace')

I don't have /sw/*.  Should I?
Does anyone have a working setup.py that installed everything 
successfully?  I've been messing around with the setup.py but after what 
"looks" like a successful build/install I still get the following:  (** 
Hmmm... just double checked, I actuall get an error about /sw/lib/mysql 
not existing - but if I comment out those lines from setup.py then it 
*seems* to build correctly...)

Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import MySQLdb
Traceback (most recent call last):
 File "<stdin>", line 1, in ?
 File "MySQLdb/__init__.py", line 27, in ?
   import _mysql
ImportError: No module named _mysql
 >>>

Here is the current state of my setup.py: (after a few attempts at 
changing variables)
Any help/suggestions would be appreciated.

############################################################################ 

#!/usr/bin/env python

"""Setup script for the MySQLdb module distribution."""

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

YES = 1
NO = 0

mysqlclient = os.getenv('mysqlclient', 'mysqlclient')
mysqlversion = tuple(map(int, string.split(os.getenv('mysqlversion', 
'4.0.18'),
'.')))
mysqloptlibs = string.split(os.getenv('mysqloptlibs', ''))
embedded_server = (mysqlclient == 'mysqld')

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

# include files and library locations should cover most platforms
include_dirs = [
   '/usr/include/mysql',
   ]
library_dirs = [
   '/usr/lib/mysql',
   ]

libraries = [mysqlclient] + mysqloptlibs

# MySQL-3.23 and newer need libz
if mysqlversion > (3,23,0):
   libraries.append("z")
#if mysqlversion > (4,0,0):
#    libraries.append("crypt")

# On some platorms, this can be used to find the shared libraries
# at runtime, if they are in a non-standard location. Doesn't
# work for Linux gcc.
runtime_library_dirs = []

# This can be used to force linking against static libraries.
extra_objects = []

# Sometimes the compiler or linker needs an extra switch to make
# things work.
extra_compile_args = []
extra_link_args = []

if sys.platform == "netbsd1":
   include_dirs = ['/usr/pkg/include/mysql']
   library_dirs = ['/usr/pkg/lib/mysql']
elif sys.platform in ("freebsd4", "openbsd3"):
   LOCALBASE = os.environ.get('LOCALBASE', '/usr/local')
   include_dirs = ['%s/include/mysql' % LOCALBASE]
   library_dirs = ['%s/lib/mysql' % LOCALBASE]
elif sys.platform == "sunos5": # Solaris 2.8 + gcc
   
runtime_library_dirs.append('/usr/local/lib:/usr/openwin/lib:/usr/dt/lib')
   extra_compile_args.append("-fPIC")
elif sys.platform == "win32": # Ugh
   include_dirs = [r'c:\mysql\include']
   library_dirs = [r'c:\mysql\lib\opt']
   libraries.extend(['zlib', 'msvcrt', 'libcmt', 'wsock32', 'advapi32'])
   extra_objects = [r'c:\mysql\lib\opt\mysqlclient.lib']
elif sys.platform == "cygwin":
   include_dirs = ['/c/mysql/include']
   library_dirs = ['/c/mysql/lib']
   extra_compile_args.append('-DMS_WIN32')
elif sys.platform[:6] == "darwin": # Mac OS X
   include_dirs.append('/sw/include/mysql')
   library_dirs.append('/sw/lib/mysql')
   extra_link_args.append('-flat_namespace')
elif sys.platform == 'linux2' and os.environ.get('HOSTTYPE') == 'alpha':
   libraries.extend(['ots', 'cpml'])
elif os.name == "posix": # UNIX-ish platforms not covered above
   pass # default should work
else:
   raise "UnknownPlatform", "sys.platform=%s, os.name=%s" % \
         (sys.platform, os.name)

long_description = \
"""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
- Thread-safety
- Thread-friendliness (threads will not block each other)
- Compatibility with MySQL-3.22 and later

This module should be mostly compatible with an older interface
written by Joe Skinner and others. However, the older version is
a) not thread-friendly, b) written for MySQL 3.21, c) apparently
not actively maintained. No code from that version is used in
MySQLdb. MySQLdb is free software.

"""

setup (# Distribution meta-data
       name = name,
       version = version,
       description = "Python interface to MySQL",
       long_description=long_description,
       author = "Andy Dustman",
       author_email = "andy at dustman.net",
       license = "GPL",
       platforms = "ALL",
       url = "http://sourceforge.net/projects/mysql-python",

       # Description of the modules and packages in the distribution

       py_modules = ["CompatMysqldb",
                     "_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_objects=extra_objects,
               extra_link_args=extra_link_args,
               extra_compile_args=extra_compile_args,
               )],
)



More information about the Pythonmac-SIG mailing list