SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



 31 January 2007
 Setting up MySQL for Python (MySQLdb) on Mac OS X


 MySQL is an excellent, very popular and open source database management system. A binary
 installation is available for Mac OS, and the process of installing MySQL on Mac OS is also very well
 documented. So just head over to MySQL.com, where you will find the binary installation, together with
 extensive installation, and usage documentation.

 To connect to MySQL from Python use MySQL for Python (MySQLdb). Get MySQLdb from
 http://sourceforge.net/projects/mysql-python/.


      1. Download MySQL from mysql.com and install the DBMS as instructed in the documentation.

      2. Make sure “Library/Python/2.3” does not have:

                            Directory “MySQL”
                            File “_mysql.pyd”
                            File “_mysql_exceptions.py”
                            File “_mysql_exceptions.pyc”

               Either uninstall MySQL for Python if a setup program was used to install it, otherwise
          manually delete them.

      3. Download and unpack MySQL for Python. At the time of writing this is MySQL-python-
         1.2.1_p2.tar.gz .

      4. Open Terminal and change to the directory where MySQLdb was unpacked to.

      5. Get rid of any previous builds that might interfere, by deleting the “build” directory if it exists.

      6. Edit the setup.py file, and change:

                      return popen(“mysql_config --%s” % what)
                              to
                      return popen(“/usr/local/mysql/bin/mysql_config --%s” % what)

      7. Cleanup any previous install attempts:

                     python setup.py clean

      8. Build MySQLdb:

                     python setup.py build

 Viola! MySQL for Python is all setup, and ready for your Python-MySQL data access code. Enjoy!



 Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it!

http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 1 of 7
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



 Filed under: Apple, Mac Dev, Python, MySQL, Mac OS X, MySQL for Python, Data Access

 Comments

 # peter said:

          one thing to note is that there is apparently an extra 'mysql' in the path that the shared object looks
          for the .dylib

          you may get an error like this--

          ImportError: dlopen(./_mysql.so, 2): Library not loaded:
          /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib

           Referenced from: ./_mysql.so

           Reason: image not found

          simple solution is to cd into the /usr/local/mysql/bin directory and enter this command:

          ln -s /usr/local/mysql/bin mysql

          which will make a symlink in the directory to itself and magically make everything available.
          (saves the space of copying everything down a level.)

       Monday, June 18, 2007 10:45 PM
 # Priyesh Jain said:

          I tried using changin the setup file in 1.2.2, but could not find the appropriate location and was too
          lazy for that :P

          Thanks a lot though ! worked like a charm with 1.2.1

          Cheers

      Friday, July 06, 2007 9:33 AM
 # Tom said:

          The location for changing mysql_config is now in site.cfg, not in the popen command as described
          above.

       Sunday, July 15, 2007 10:21 PM
 # Victor said:

          The mysql installation from fink doesn't seem to have mysql_config, neither in the client nor
          server install.

       Monday, July 16, 2007 5:16 PM
 # Victor said:

          Ah. The mysql_config program is in the mysql_dev package.


http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 2 of 7
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



      Monday, July 16, 2007 5:42 PM
 # David Preece said:

          I've been using MAMP and it does not appear that you need to muck about with the path for
          mysql_config. However, I still can't get it to build - GCC complains "error: my_config.h: No such
          file or directory" then it just snowballs from there :(

      Thursday, July 19, 2007 6:49 AM
 # Łukasz Adamczak said:

          I'm also using MAMP and trying to build MySQLdb. Apparently the include files for mysql don't
          come with MAMP.

          mysql-config --include

          returns -I/Applications/MAMP/Library/include/mysql, but this path doesn't exist.

          Will probably need to install the official version.

      Thursday, July 19, 2007 11:15 PM
 # Martin Byröd said:

          I installed the lastest mysql version from mysql.com and I also cant get it to build. For me the
          problem is a missing "sys/types.h". Does anyone know what that means?

       Tuesday, August 14, 2007 5:29 PM
 # Toni Menzel said:

          Correction to the "ln -s .." approach metioned about by Peter: there is a typo using bin instead of
          lib.

          So, you have to switch to /usr/local/mysql/lib

          create a symlink like this:

          ln -s /usr/local/mysql/lib mysql

          cheers,

          Toni

       Tuesday, September 11, 2007 9:11 PM
 # Lisa Friedland said:

          I made the mistake of upgrading to the newest Python version, 2.5.1, when trying to install
          mysqldb, and then I had a series of (varying) errors trying to build mysqldb. Save yourself the
          trouble! Use MacPython 2.4, then use the installer for mysqldb found at
          pythonmac.org/.../index.html. (Of course, this advice only holds as long as there's no installer for
          mysqldb under Python 2.5.)

      Monday, September 17, 2007 9:28 PM
 # Venkatesh said:


http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 3 of 7
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



          ---------------

          "Correction to the "ln -s .." approach metioned about by Peter: there is a typo using bin instead of
          lib.

          So, you have to switch to /usr/local/mysql/lib

          create a symlink like this:

          ln -s /usr/local/mysql/lib mysql"

          -----------------

          Thank you Tony and also Peter!! It fixed my problem.

       Sunday, September 30, 2007 9:54 AM
 # Jakob Løkke Madsen said:

          ____________________

          Correction to the "ln -s .." approach metioned about by Peter: there is a typo using bin instead of
          lib.

          So, you have to switch to /usr/local/mysql/lib

          create a symlink like this:

          ln -s /usr/local/mysql/lib mysql

          cheers,

          Toni

          _____________

          Thanks!!! Now it works for me as well! Wonderful!

       Tuesday, October 23, 2007 6:04 PM
 # Alessandro Censoni said:

          I trie to install mysql-python 1.2.2 but I have a lot of errors. I have install MySQL 5.0.45 and
          python 2.5.1.I use Mac OS X 10.4.9 and when I trie to build mysqldb i have the following error:

          >sh: line 1: mysql_config: command not found

          >Traceback (most recent call last):

           >File "setup.py", line 16, in <module>

             >metadata, options = get_config()

           >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", line 43, in
          get_config

http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 4 of 7
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



              >libs = mysql_config("libs_r")

          >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", >line 24, in
          mysql_config

              >raise EnvironmentError, "%s not found" % mysql_config.path

          >EnvironmentError: mysql_config not found

          If i trie to install the mysqldb, however I have the following error:

          >sh: line 1: /usr/local/bin/mysql_config: No such file or directory

          >Traceback (most recent call last):

          >File "setup.py", line 16, in <module>

          >metadata, options = get_config()

          >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", line 43, in
          get_config

          >libs = mysql_config("libs_r")

          >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", line 24, in
          mysql_config

           >raise EnvironmentError, "%s not found" % mysql_config.path

          >EnvironmentError: /usr/local/bin/mysql_config not found

          Infatti, ho semplicemente 'decommentato' una riga del file dove c'era mysql_config =
          /usr/local/bin/mysql_config.

          I don't know where I have to do the change suggested in the guide and relative comments. In the
          site.cfg I don't know what I have to change. I also trie to edit the setup.py of mysqlpython-
          1.2.1_p2 but I have the following error:

          >File "setup.py", line 26

          >     f = popen(“/usr/local/mysql/bin/mysql_config --%s” % what)

          >              ^

          >SyntaxError: invalid syntax

          Can somebody help me?

          Thanks a lot

          Tuesday, October 30, 2007 11:36 AM

          Home

http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 5 of 7
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



 n.code


          RSS
          Atom
          Comments RSS

 Recent Posts

          SQL Server Error: OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
          IUnknown::QueryInterface returned 0x80004005: The provider did not give any information about
          the error.]
          Random Ramblings Over Ruby On Microsoft .NET
          Common .NET Memory Issues
          Bulk Update and Insert of Object State Stored by SQL Server 2000, Using .NET (C#)
          .NET Memory Leak: XmlSerializing your way to a Memory Leak

 Tags

          .config
          .NET
          Apple
          AppSettings
          C#
          Configuration
          Data Access
          DataBase Management
          Delegates
          IronRuby
          Java
          Mac Dev
          Mac OS X
          Martin Fowler
          Memory Issues
          Mircosoft
          MySQL
          MySQL for Python
          NameValueCollection
          NameValueSectionHandler
          Open Source
          Python
          Ruby
          Serialization
          SQL Server
          Streams
          Threading
          XML

 Archives



http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 6 of 7
Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code                                             11/07/2007 11:23 AM



          August 2007 (2)
          June 2007 (1)
          May 2007 (1)
          April 2007 (1)
          January 2007 (2)

 Search

                                    Go

 Navigation

          Home
          Careers
          Downloads
          Support




http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx            Page 7 of 7

Weitere ähnliche Inhalte

Was ist angesagt?

Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with AugeasPuppet
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop InstallMike Frampton
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Cosimo Streppone
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013grim_radical
 
Chef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
Chef Workshop: Setup Environment with Chef,Vagrant, and BerkshelfChef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
Chef Workshop: Setup Environment with Chef,Vagrant, and BerkshelfJun Sakata
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase RubySergey Avseyev
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installationMinh Tran
 
Using docker for data science - part 2
Using docker for data science - part 2Using docker for data science - part 2
Using docker for data science - part 2Calvin Giles
 
rake puppetexpert:create - Puppet Camp Silicon Valley 2014
rake puppetexpert:create - Puppet Camp Silicon Valley 2014rake puppetexpert:create - Puppet Camp Silicon Valley 2014
rake puppetexpert:create - Puppet Camp Silicon Valley 2014nvpuppet
 
Using python and docker for data science
Using python and docker for data scienceUsing python and docker for data science
Using python and docker for data scienceCalvin Giles
 
Deploying Django with Ansible
Deploying Django with AnsibleDeploying Django with Ansible
Deploying Django with Ansibleandrewmirskynet
 
Single node hadoop cluster installation
Single node hadoop cluster installation Single node hadoop cluster installation
Single node hadoop cluster installation Mahantesh Angadi
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setupMohammad_Tariq
 
Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12
Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12
Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12akira6592
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REXSaewoong Lee
 
A.I. Exercise.
A.I. Exercise.A.I. Exercise.
A.I. Exercise.Mario Cho
 
Docker for data science
Docker for data scienceDocker for data science
Docker for data scienceCalvin Giles
 
Embedded Linux Odp
Embedded Linux OdpEmbedded Linux Odp
Embedded Linux Odpghessler
 

Was ist angesagt? (20)

Configuration Surgery with Augeas
Configuration Surgery with AugeasConfiguration Surgery with Augeas
Configuration Surgery with Augeas
 
An example Hadoop Install
An example Hadoop InstallAn example Hadoop Install
An example Hadoop Install
 
Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013Puppet at Opera Sofware - PuppetCamp Oslo 2013
Puppet at Opera Sofware - PuppetCamp Oslo 2013
 
Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013Puppet: Eclipsecon ALM 2013
Puppet: Eclipsecon ALM 2013
 
Chef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
Chef Workshop: Setup Environment with Chef,Vagrant, and BerkshelfChef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
Chef Workshop: Setup Environment with Chef,Vagrant, and Berkshelf
 
Getting Started with Couchbase Ruby
Getting Started with Couchbase RubyGetting Started with Couchbase Ruby
Getting Started with Couchbase Ruby
 
Hadoop single cluster installation
Hadoop single cluster installationHadoop single cluster installation
Hadoop single cluster installation
 
Using docker for data science - part 2
Using docker for data science - part 2Using docker for data science - part 2
Using docker for data science - part 2
 
rake puppetexpert:create - Puppet Camp Silicon Valley 2014
rake puppetexpert:create - Puppet Camp Silicon Valley 2014rake puppetexpert:create - Puppet Camp Silicon Valley 2014
rake puppetexpert:create - Puppet Camp Silicon Valley 2014
 
Using python and docker for data science
Using python and docker for data scienceUsing python and docker for data science
Using python and docker for data science
 
Deploying Django with Ansible
Deploying Django with AnsibleDeploying Django with Ansible
Deploying Django with Ansible
 
Single node hadoop cluster installation
Single node hadoop cluster installation Single node hadoop cluster installation
Single node hadoop cluster installation
 
Hadoop single node setup
Hadoop single node setupHadoop single node setup
Hadoop single node setup
 
Light my-fuse
Light my-fuseLight my-fuse
Light my-fuse
 
Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12
Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12
Ansibleではじめるサーバー・ネットワークの自動化 (Ansible2.7情報つき)2018/10/12
 
Run wordcount job (hadoop)
Run wordcount job (hadoop)Run wordcount job (hadoop)
Run wordcount job (hadoop)
 
Ansible : what's ansible & use case by REX
Ansible :  what's ansible & use case by REXAnsible :  what's ansible & use case by REX
Ansible : what's ansible & use case by REX
 
A.I. Exercise.
A.I. Exercise.A.I. Exercise.
A.I. Exercise.
 
Docker for data science
Docker for data scienceDocker for data science
Docker for data science
 
Embedded Linux Odp
Embedded Linux OdpEmbedded Linux Odp
Embedded Linux Odp
 

Ähnlich wie Setup MySQLdb for Python on Mac

Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installerGiuseppe Maxia
 
Mysql wp cluster_quickstart_windows
Mysql wp cluster_quickstart_windowsMysql wp cluster_quickstart_windows
Mysql wp cluster_quickstart_windowsRogério Rocha
 
Serving Moodle Presentation
Serving Moodle PresentationServing Moodle Presentation
Serving Moodle Presentationwebhostingguy
 
Multiple instance on windows
Multiple instance on windowsMultiple instance on windows
Multiple instance on windowsVasudeva Rao
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAsMark Leith
 
Get mysql clusterrunning-windows
Get mysql clusterrunning-windowsGet mysql clusterrunning-windows
Get mysql clusterrunning-windowsJoeSg
 
MySQL for Beginners - part 1
MySQL for Beginners - part 1MySQL for Beginners - part 1
MySQL for Beginners - part 1Ivan Zoratti
 
Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册Yiwei Ma
 
Ruby and Rails Packaging to Production
Ruby and Rails Packaging to ProductionRuby and Rails Packaging to Production
Ruby and Rails Packaging to ProductionFabio Kung
 
Oracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOsama Mustafa
 
20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnddo_aki
 

Ähnlich wie Setup MySQLdb for Python on Mac (20)

Dbdeployer, the universal installer
Dbdeployer, the universal installerDbdeployer, the universal installer
Dbdeployer, the universal installer
 
Mysql wp cluster_quickstart_windows
Mysql wp cluster_quickstart_windowsMysql wp cluster_quickstart_windows
Mysql wp cluster_quickstart_windows
 
Mysql
Mysql Mysql
Mysql
 
Mysql all
Mysql allMysql all
Mysql all
 
My Sq Ldb Tut
My Sq Ldb TutMy Sq Ldb Tut
My Sq Ldb Tut
 
Serving Moodle Presentation
Serving Moodle PresentationServing Moodle Presentation
Serving Moodle Presentation
 
Multiple instance on windows
Multiple instance on windowsMultiple instance on windows
Multiple instance on windows
 
Mysql all
Mysql allMysql all
Mysql all
 
Mysql ppt
Mysql pptMysql ppt
Mysql ppt
 
MySQL for Oracle DBAs
MySQL for Oracle DBAsMySQL for Oracle DBAs
MySQL for Oracle DBAs
 
Joy of Unix
Joy of UnixJoy of Unix
Joy of Unix
 
Get mysql clusterrunning-windows
Get mysql clusterrunning-windowsGet mysql clusterrunning-windows
Get mysql clusterrunning-windows
 
MySQL for Beginners - part 1
MySQL for Beginners - part 1MySQL for Beginners - part 1
MySQL for Beginners - part 1
 
Php mysql-tutorial-en
Php mysql-tutorial-enPhp mysql-tutorial-en
Php mysql-tutorial-en
 
Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册Nginx 0.8.x 安装手册
Nginx 0.8.x 安装手册
 
Mysqlnd uh
Mysqlnd uhMysqlnd uh
Mysqlnd uh
 
Ruby and Rails Packaging to Production
Ruby and Rails Packaging to ProductionRuby and Rails Packaging to Production
Ruby and Rails Packaging to Production
 
Capistrano Rails
Capistrano RailsCapistrano Rails
Capistrano Rails
 
Oracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLinkOracle to MySQL DatabaseLink
Oracle to MySQL DatabaseLink
 
20141011 mastering mysqlnd
20141011 mastering mysqlnd20141011 mastering mysqlnd
20141011 mastering mysqlnd
 

Mehr von AkramWaseem

Mseduebookexcitinglearningweb Final 120914022330 Phpapp02
Mseduebookexcitinglearningweb Final 120914022330 Phpapp02Mseduebookexcitinglearningweb Final 120914022330 Phpapp02
Mseduebookexcitinglearningweb Final 120914022330 Phpapp02AkramWaseem
 
Xml Messaging With Soap
Xml Messaging With SoapXml Messaging With Soap
Xml Messaging With SoapAkramWaseem
 
Html5 Cheat Sheet
Html5 Cheat SheetHtml5 Cheat Sheet
Html5 Cheat SheetAkramWaseem
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags AdvancedAkramWaseem
 
Ascii Table Characters
Ascii Table CharactersAscii Table Characters
Ascii Table CharactersAkramWaseem
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1AkramWaseem
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python DbapiAkramWaseem
 
Random And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiRandom And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiAkramWaseem
 
Internet Programming With Python Presentation
Internet Programming With Python PresentationInternet Programming With Python Presentation
Internet Programming With Python PresentationAkramWaseem
 
Docs Python Org Howto Webservers Html
Docs Python Org Howto Webservers HtmlDocs Python Org Howto Webservers Html
Docs Python Org Howto Webservers HtmlAkramWaseem
 

Mehr von AkramWaseem (20)

Mseduebookexcitinglearningweb Final 120914022330 Phpapp02
Mseduebookexcitinglearningweb Final 120914022330 Phpapp02Mseduebookexcitinglearningweb Final 120914022330 Phpapp02
Mseduebookexcitinglearningweb Final 120914022330 Phpapp02
 
Xml Messaging With Soap
Xml Messaging With SoapXml Messaging With Soap
Xml Messaging With Soap
 
Xhtml Basics
Xhtml BasicsXhtml Basics
Xhtml Basics
 
Uml Tutorial
Uml TutorialUml Tutorial
Uml Tutorial
 
Xhtml Basics
Xhtml BasicsXhtml Basics
Xhtml Basics
 
Html5 Cheat Sheet
Html5 Cheat SheetHtml5 Cheat Sheet
Html5 Cheat Sheet
 
Ajax Tags Advanced
Ajax Tags AdvancedAjax Tags Advanced
Ajax Tags Advanced
 
Ascii Table Characters
Ascii Table CharactersAscii Table Characters
Ascii Table Characters
 
Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1Www Kitebird Com Articles Pydbapi Html Toc 1
Www Kitebird Com Articles Pydbapi Html Toc 1
 
Scripts Python Dbapi
Scripts Python DbapiScripts Python Dbapi
Scripts Python Dbapi
 
Random And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python CgiRandom And Dynamic Images Using Python Cgi
Random And Dynamic Images Using Python Cgi
 
Pydbapi
PydbapiPydbapi
Pydbapi
 
Internet Programming With Python Presentation
Internet Programming With Python PresentationInternet Programming With Python Presentation
Internet Programming With Python Presentation
 
Cgi
CgiCgi
Cgi
 
Docs Python Org Howto Webservers Html
Docs Python Org Howto Webservers HtmlDocs Python Org Howto Webservers Html
Docs Python Org Howto Webservers Html
 
Handson Python
Handson PythonHandson Python
Handson Python
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Python 3 Days
Python  3 DaysPython  3 Days
Python 3 Days
 
Tutorial Python
Tutorial PythonTutorial Python
Tutorial Python
 
Tutor Py
Tutor PyTutor Py
Tutor Py
 

Setup MySQLdb for Python on Mac

  • 1. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM 31 January 2007 Setting up MySQL for Python (MySQLdb) on Mac OS X MySQL is an excellent, very popular and open source database management system. A binary installation is available for Mac OS, and the process of installing MySQL on Mac OS is also very well documented. So just head over to MySQL.com, where you will find the binary installation, together with extensive installation, and usage documentation. To connect to MySQL from Python use MySQL for Python (MySQLdb). Get MySQLdb from http://sourceforge.net/projects/mysql-python/. 1. Download MySQL from mysql.com and install the DBMS as instructed in the documentation. 2. Make sure “Library/Python/2.3” does not have: Directory “MySQL” File “_mysql.pyd” File “_mysql_exceptions.py” File “_mysql_exceptions.pyc” Either uninstall MySQL for Python if a setup program was used to install it, otherwise manually delete them. 3. Download and unpack MySQL for Python. At the time of writing this is MySQL-python- 1.2.1_p2.tar.gz . 4. Open Terminal and change to the directory where MySQLdb was unpacked to. 5. Get rid of any previous builds that might interfere, by deleting the “build” directory if it exists. 6. Edit the setup.py file, and change: return popen(“mysql_config --%s” % what) to return popen(“/usr/local/mysql/bin/mysql_config --%s” % what) 7. Cleanup any previous install attempts: python setup.py clean 8. Build MySQLdb: python setup.py build Viola! MySQL for Python is all setup, and ready for your Python-MySQL data access code. Enjoy! Share this post: email it! | bookmark it! | digg it! | reddit! | kick it! | live it! http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 1 of 7
  • 2. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM Filed under: Apple, Mac Dev, Python, MySQL, Mac OS X, MySQL for Python, Data Access Comments # peter said: one thing to note is that there is apparently an extra 'mysql' in the path that the shared object looks for the .dylib you may get an error like this-- ImportError: dlopen(./_mysql.so, 2): Library not loaded: /usr/local/mysql/lib/mysql/libmysqlclient_r.15.dylib Referenced from: ./_mysql.so Reason: image not found simple solution is to cd into the /usr/local/mysql/bin directory and enter this command: ln -s /usr/local/mysql/bin mysql which will make a symlink in the directory to itself and magically make everything available. (saves the space of copying everything down a level.) Monday, June 18, 2007 10:45 PM # Priyesh Jain said: I tried using changin the setup file in 1.2.2, but could not find the appropriate location and was too lazy for that :P Thanks a lot though ! worked like a charm with 1.2.1 Cheers Friday, July 06, 2007 9:33 AM # Tom said: The location for changing mysql_config is now in site.cfg, not in the popen command as described above. Sunday, July 15, 2007 10:21 PM # Victor said: The mysql installation from fink doesn't seem to have mysql_config, neither in the client nor server install. Monday, July 16, 2007 5:16 PM # Victor said: Ah. The mysql_config program is in the mysql_dev package. http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 2 of 7
  • 3. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM Monday, July 16, 2007 5:42 PM # David Preece said: I've been using MAMP and it does not appear that you need to muck about with the path for mysql_config. However, I still can't get it to build - GCC complains "error: my_config.h: No such file or directory" then it just snowballs from there :( Thursday, July 19, 2007 6:49 AM # Łukasz Adamczak said: I'm also using MAMP and trying to build MySQLdb. Apparently the include files for mysql don't come with MAMP. mysql-config --include returns -I/Applications/MAMP/Library/include/mysql, but this path doesn't exist. Will probably need to install the official version. Thursday, July 19, 2007 11:15 PM # Martin Byröd said: I installed the lastest mysql version from mysql.com and I also cant get it to build. For me the problem is a missing "sys/types.h". Does anyone know what that means? Tuesday, August 14, 2007 5:29 PM # Toni Menzel said: Correction to the "ln -s .." approach metioned about by Peter: there is a typo using bin instead of lib. So, you have to switch to /usr/local/mysql/lib create a symlink like this: ln -s /usr/local/mysql/lib mysql cheers, Toni Tuesday, September 11, 2007 9:11 PM # Lisa Friedland said: I made the mistake of upgrading to the newest Python version, 2.5.1, when trying to install mysqldb, and then I had a series of (varying) errors trying to build mysqldb. Save yourself the trouble! Use MacPython 2.4, then use the installer for mysqldb found at pythonmac.org/.../index.html. (Of course, this advice only holds as long as there's no installer for mysqldb under Python 2.5.) Monday, September 17, 2007 9:28 PM # Venkatesh said: http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 3 of 7
  • 4. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM --------------- "Correction to the "ln -s .." approach metioned about by Peter: there is a typo using bin instead of lib. So, you have to switch to /usr/local/mysql/lib create a symlink like this: ln -s /usr/local/mysql/lib mysql" ----------------- Thank you Tony and also Peter!! It fixed my problem. Sunday, September 30, 2007 9:54 AM # Jakob Løkke Madsen said: ____________________ Correction to the "ln -s .." approach metioned about by Peter: there is a typo using bin instead of lib. So, you have to switch to /usr/local/mysql/lib create a symlink like this: ln -s /usr/local/mysql/lib mysql cheers, Toni _____________ Thanks!!! Now it works for me as well! Wonderful! Tuesday, October 23, 2007 6:04 PM # Alessandro Censoni said: I trie to install mysql-python 1.2.2 but I have a lot of errors. I have install MySQL 5.0.45 and python 2.5.1.I use Mac OS X 10.4.9 and when I trie to build mysqldb i have the following error: >sh: line 1: mysql_config: command not found >Traceback (most recent call last): >File "setup.py", line 16, in <module> >metadata, options = get_config() >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", line 43, in get_config http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 4 of 7
  • 5. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM >libs = mysql_config("libs_r") >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", >line 24, in mysql_config >raise EnvironmentError, "%s not found" % mysql_config.path >EnvironmentError: mysql_config not found If i trie to install the mysqldb, however I have the following error: >sh: line 1: /usr/local/bin/mysql_config: No such file or directory >Traceback (most recent call last): >File "setup.py", line 16, in <module> >metadata, options = get_config() >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", line 43, in get_config >libs = mysql_config("libs_r") >File "/Users/alessandrocensoni/Desktop/MySQL-python-1.2.2/setup_posix.py", line 24, in mysql_config >raise EnvironmentError, "%s not found" % mysql_config.path >EnvironmentError: /usr/local/bin/mysql_config not found Infatti, ho semplicemente 'decommentato' una riga del file dove c'era mysql_config = /usr/local/bin/mysql_config. I don't know where I have to do the change suggested in the guide and relative comments. In the site.cfg I don't know what I have to change. I also trie to edit the setup.py of mysqlpython- 1.2.1_p2 but I have the following error: >File "setup.py", line 26 > f = popen(“/usr/local/mysql/bin/mysql_config --%s” % what) > ^ >SyntaxError: invalid syntax Can somebody help me? Thanks a lot Tuesday, October 30, 2007 11:36 AM Home http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 5 of 7
  • 6. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM n.code RSS Atom Comments RSS Recent Posts SQL Server Error: OLE DB error trace [OLE/DB Provider 'SQLOLEDB' IUnknown::QueryInterface returned 0x80004005: The provider did not give any information about the error.] Random Ramblings Over Ruby On Microsoft .NET Common .NET Memory Issues Bulk Update and Insert of Object State Stored by SQL Server 2000, Using .NET (C#) .NET Memory Leak: XmlSerializing your way to a Memory Leak Tags .config .NET Apple AppSettings C# Configuration Data Access DataBase Management Delegates IronRuby Java Mac Dev Mac OS X Martin Fowler Memory Issues Mircosoft MySQL MySQL for Python NameValueCollection NameValueSectionHandler Open Source Python Ruby Serialization SQL Server Streams Threading XML Archives http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 6 of 7
  • 7. Setting up MySQL for Python (MySQLdb) on Mac OS X - n.code 11/07/2007 11:23 AM August 2007 (2) June 2007 (1) May 2007 (1) April 2007 (1) January 2007 (2) Search Go Navigation Home Careers Downloads Support http://dotnet.org.za/ncode/archive/2007/01/31/setting-up-mysql-for-python-mysqldb-on-mac-os-x-2.aspx Page 7 of 7