Python+django+mysql Configuration under Mac

Source: Internet
Author: User

Today, when setting up the DJANGO+MYSQL environment, I encountered a few problems and recorded it.

Installation environment: OS X 10.10 operating system, Python 2.7.

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 describes two common installation methods for MYSQLDB:

Download the installation or Pip install Mysql-python. 

Source Installation

Download MySQLdb Source Code

Here is the version of 1.2.5

https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c

Unzip the download, and then execute the following command in Terminal Terminal:

$  CD mysql-python-1.2.5

Then modify the Site.cfg to modify the following:

by #mysql_config =/usr/local/bin/mysql_config

Change to Mysql_config =/usr/local/mysql/bin/mysql_config

Otherwise, there will be no problem finding MySQL config:

File "/tmp/easy_install-nhssgl/mysql-python-1.2.2/setup_posix.py", line, in Mysql_config
Environmenterror:mysql_config not found

Then modify the _MYSQL.C and comment out the 37th to 39th line as follows:

#ifndef uint//#define UINT unsigned int//#endif


Otherwise, it will appear:

In file included from/usr/local/mysql/include/mysql.h:47, from                 _mysql.c:40:/usr/include/sys/types.h:92:error: Duplicate ' unsigned '/usr/include/sys/types.h:92:error:two or more data types in declaration Specifierserror:command ' GC C ' failed with exit status 1

Then use Python./setup.py build Compilation

$ python./setup.py Build

Then use Python./setup.py Install Installation

$ sudo python./setup.py Installpassword:
installing MYSQLDB with Pip

execute in Terminal: $ pip install mysql-python

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:

Path="/usr/local/mysql/bin:${path}"

Export PATH

Export dyld_library_path=/usr/local/mysql/lib/

Export Versioner_python_prefer_64_bit=no

Export Versioner_python_prefer_32_bit=yes

Among them versioner_python_prefer_64_bit and versioner_python_prefer_64_bit according to their own installation of MySQL to choose.

Also provide a PIP installation can not find the Mysql_config solution, enter the following command in the terminal:

$ sudo ln-s/usr/local/mysql/bin/*/usr/bin

Here, the Mysql-python package should be installed basically smoothly.

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

Test

Use the following command to test:

$ cd ~$ Pythonpython 2.5.1 (r251:54863, APR, 22:57:26) [GCC 4.0.1 (Apple Inc. build 5465)] on Darwintype "Help", " Copyright "," credits "or" license "for more information.>>> import mysqldb>>> mysqldb.apilevel ' 2.0 ' >>> Import django>>> Print Django. VERSION (1, 0, ' final ')
Common errors

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

Python+django+mysql Configuration under Mac

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.