In the middle of a lot of problems, now put the information found here, for reference only
http://blog.csdn.net/janronehoo/article/details/25207825
Installation environment: OS X operating system, Python 2.7.3.
MySQLdb is actually included in the Mysql-python package, so you should search for Mysql-python whether you download or search in PIP.
The following is a description of the MySQLdb two common installation methods, download installation or PIP installation Mysql-python.
Download MySQLdb
In SourceForge you can download Mysql-python-1.2.4b4.tar, unzip it after downloading, and then execute the following command in Terminal Terminal:
new-host-3:~ ifantastic$ cd/users/ifantastic/downloads/mysql-python-1.2.4b4
NEW-HOST-3:MYSQL-PYTHON-1.2.4B4 ifantastic$ python setup.py install
Installing MYSQLDB with PIP
Execute in Terminal:
new-host-Install Mysql-python
Whether you are installing online or downloading an installation, you may encounter the first error message:
Not found
It is recommended to use PIP installation because the version I downloaded from SourceForge is not as new as the PIP. If you want to upgrade the Mysql-python version, you can use the following command:
$ easy_install Mysql-python--upgrade
[Note] If you do not follow the instructions below to resolve the installation errors, the upgrade will also fail for the same cause of error.
Resolve Mysql_config not found error
When you install the Mac version of MySQL by default, the Mysql_config file is generated in the/usr/local/mysql/bin directory.
Therefore, the solution to download the installation is: Locate the Site.cfg file in the Mysql-python installation package, open it, and locate the following:
# the path to mysql_config.< Span style= "line-height:1.5!important; margin:0px; Color: #008000; padding:0px; " ># only use this if Mysql_ Config is isn't on your PATH, or you have some weird# setup that requires it.< Span style= "line-height:1.5!important; margin:0px; Color: #008000; padding:0px; " ># Mysql_config =/usr/ Local/bin/mysql_config
Remove the last sentence first and modify it as follows:
Mysql_config =/usr/local/mysql/bin/mysql_config
Then execute:
$ python setup.py Install
Generally speaking, the installation can be completed at this point, but there are still problems, as described below.
There is no way to modify the Site.cfg file when using PIP installation, so you can resolve errors that cannot be found by modifying OS X's system environment variables.
Modify OS x environment variable: Open terminal, use VIM in terminal to open "~/.bash_profile", if no vim is installed, then show hidden file Open with text editor, the operation here is no longer described. In. Bash_profile, add the following:
"/usr/local/mysql/bin:$ {PATH} "export pathexport dyld_library_path=/usr/local/mysql/lib/export versioner_python_prefer_64_bit=
Among them versioner_python_prefer_64_bit and versioner_python_prefer_64_bit according to their own installation of MySQL to choose.
In addition, a PIP installation can not find the Mysql_config solution (I did not verify), enter the following command in the terminal:
$ sudo ln-s/usr/local/mysql/bin/*/usr/bin
Well, here, Mysql-python package should be basically smooth installation.
Resolve Reason:image not found error
After installing the Mysql-python package, let us import mysqldb, there is an error, the last line of error is written reason:image not found.
The workaround is to execute at the terminal:
$ sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18. dylib$ sudo ln-s/usr/local/ Mysql/lib/usr/local/mysql/lib/mysql
Error:
Clang:error: Unknown argument: '-mno-fused-madd ' [-wunused-command-line-argument-hard-error-in-future]
clang:note:this 'll be a hard error (cannot is downgraded to a warning) in the future
Verified on-line: Http://www.tuicool.com/articles/zI7Vzu, seemingly Mac OS Xcode from 5.1 to compiler rules for unknown parameter incoming as error, We need to downgrade this error to warning using archflags, so the final installation command should look like this:
sudo archflags=-wno-error=unused-command-line-argument-hard-error-in-future python setup.py build
Reference
Http://www.cnblogs.com/macro-cheng/archive/2011/10/25/mysql-001.html
http://www.liuhuadong.com/archives/1628
MYSQLDB error in installing Python module under Mac OS X and resolution
Using Python on your Mac, there are more problems than CentOS, and here's a solution to this problem.
The following error is prompted with MySQLdb in your Mac:
Traceback (most recent): file "./b", line +, in import mysqldb File "/library/python/2.7/ site-packages/mysql_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/mysqldb/__init__.py ", line +, in import _ Mysqlimporterror:dlopen (/library/python/2.7/site-packages/mysql_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_ Mysql.so, 2): no suitable image found. Did Find:/library/python/2.7/site-packages/mysql_python-1.2.4b4-py2.7-macosx-10.8-intel.egg/_mysql.so:mach-o, But wrong architecture
The reason is that because Macs are different from other Linux, some dynamic libraries need to be compiled manually, especially if the Mac is a 64-bit operating system, so turn this option on to recompile. To do this, edit under the current User:
Vim ~/.bash_profile
Add the following (remove line numbers):
Path= "/usr/local/mysql/bin:${path}" export PATH from export DYLD_LIBRARY_PATH=/USR/LOCAL/MYSQL/LIB/25 export Versioner_python_prefer_64_bit=yes Export Versioner_python_prefer_32_bit=yes
Then load the modified configuration:
SOURCE ~/.bash_profile
Then enter the Mysqlpython directory and compile the installation:
Python setup.py buildpython setup.py Install
It is important to note that Bash_profile are modified and loaded under different users, otherwise the non-current user cannot take effect.
Http://rabbit52.com/2012/desktopos/mac/mac-dyld_library_path-error
After you install MySQL and python-mysqldb on your MAC, you cannot import the "Dyld_library_path" environment variable in Python, which is usually added
Export dyld_library_path= "/usr/local/mysql/lib: $DYLD _library_path"
Resolved, but doing so will cause an error when the terminal executes the sudo command
DYLD:DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid
Actually, this is a bug in Mountain Lion.
But there is a way to solve, if you have the cause of the problem and I, then execute the following command and delete the top of the environment variable configuration is OK
sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18.dylib