How to Install MySQLdb (Python Data Access Library to MySQL) on MAC Os X

Installing MySQLdb on Mac OS X

Ack. I feel your pain. I spent a really long time also trying to get MySQL working with Python 2.6 on Snow Leopard using a Macbook Air and had lots of architecture problems. What ended up solving it for me, was making sure both my Python and MySQL installations were using a 32 bit architecture like my Snow Leopard was.

I wrote about my solution here, so maybe that'll help:

http://www.markliu.me/2010/jun/09/mysql-and-python-on-32-bit-snow-leopard/

Good luck...

Installing MySQL Python on Mac OS X

Another option is to use pymysql it is a pure Python client connection to MySQL so you don't have to mess around with compiling, a good exercise, but it can be frustrating if you are just trying to get something done. pymysql follows the same API as MySQLdb, it can essentially be used as a drop in replacement.

Also, it used to be that MySQLdb, did not work with Python 3, but this may have changed, pymysql didn't have that problem which also induced me to switch, this may have changed though. pymysql can be slower than MySQLdb but you'll have to see if you notice that, it is also under a different license (MIT for pymysql, GPL for MySQLdb)

Help installing MySQLdb for Python under Mac OS X

Try macports:

$ port search python | grep mysql
py-mysql @1.2.2 (python, devel, databases)
Python interface to mysql
py25-mysql @1.2.2 (python, devel, databases)
Python interface to mysql
py26-mysql @1.2.3 (python, devel, databases)
py27-mysql @1.2.2 (python, devel, databases)
Python interface to mysql

installing MySQLdb for Python 2.6 on OSX

It's not looking for 'mysql', it's looking for 'mysql_config'. Try running 'which mysql_config' from bash. It probably won't be found. That's why the build isn't finding it either. Try running 'locate mysql_config' and see if anything comes back. The path to this binary needs to be either in your shell's $PATH environment variable, or it needs to be explicitly in the setup.py file for the module assuming it's looking in some specific place for that file.

If you installed mysql from source in /usr/local, I believe the file will be found at /usr/local/mysql/bin/mysql_config

cannot install MySQLdb on virtualenv (Mac 10.13)

The answer in this other question solved the problem, below is the command I used to make it work.

export DYLD_FALLBACK_LIBRARY_PATH=/anaconda2/lib/:$DYLD_FALLBACK_LIBRARY_PATH

A few notes however...

  • I had to run this command WITHIN my virtual environment for it to work, not my global environment
  • I was told this is a problem with Anaconda managing my packages and my virtual environment variables not being able to find the correct paths
  • You'll notice that my folder is "~/anaconda2/..." check to see where your lib files are installed on your global environment and make sure you adjust the directory name accordingly
  • Also I was suggested to keep this command in an initialization file for my virtual environment, that way whenever my virtual environment loads, this command is already executed

How to install Python MySQLdb module using pip?

It's easy to do, but hard to remember the correct spelling:

pip install mysqlclient

If you need 1.2.x versions (legacy Python only), use pip install MySQL-python

Note: Some dependencies might have to be in place when running the above command. Some hints on how to install these on various platforms:

Ubuntu 14, Ubuntu 16, Debian 8.6 (jessie)

sudo apt-get install python-pip python-dev libmysqlclient-dev

Fedora 24:

sudo dnf install python python-devel mysql-devel redhat-rpm-config gcc

Mac OS

brew install mysql-connector-c

if that fails, try

brew install mysql


Related Topics



Leave a reply



Submit