Python + Django + mysql configuration in MAC, pythondjango

Source: Internet
Author: User

Python + Django + mysql configuration in MAC, pythondjango

Today, I encountered a problem when setting up the Django + mysql environment and recorded it.

 

Installation environment: OS X 10.10, Python 2.7.

MySQLdb is actually included in the MySQL-python package. Therefore, whether downloaded or searched in pip, you should search for MySQL-python.

 

The following describes two common installation methods for MySQLdb:

Download and install MySQL-python by using pip.

Source code Installation

Download MySQLdb source code

The following is version 1.2.5.

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

Download and decompress the package, and then execute the following command in Terminal:

$ MySQL-python-1.2.5 cd

Modify site. cfg and modify the following content:

By # mysql_config =/usr/local/bin/mysql_config

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

Otherwise, MySQL config cannot be found:

File "/tmp/easy_install-nHSsgl/MySQL-python-1.2.2/setup_posix.py", line 24, in mysql_config
EnvironmentError: mysql_config not found

Modify _ mysql. c and comment out lines 37th to 39, as shown below:

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


Otherwise:

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 'gcc' failed with exit status 1

Then use python./setup. py build to compile

$ python ./setup.py build

Then install python./setup. py install

$ sudo python ./setup.py installPassword:
Install MySQLdb using pip

Run $ pip install MySQL-python on the terminal.

During pip installation, there is no way to modify the site. cfg file. Therefore, you can modify the OS X system environment variable to solve the problem of not finding mysql_config.

Modify OS X environment variables: Open the terminal and use vim to open "~ /. Bash_profile ". If vim is not installed, the hidden file is displayed and opened in a text editor. This will not be repeated here. Add the following content to. bash_profile:

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

VERSIONER_PYTHON_PREFER_64_BIT and VERSIONER_PYTHON_PREFER_64_BIT are selected based on their installed MySQL.

In addition, we provide a solution for installing pip that cannot find mysql_config. Enter the following command in the terminal:

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

By now, the MySQL-python package should be installed smoothly.

 

Solve the Reason: image not found Error

After installing the MySQL-python package, let's import MySQLdb. An error occurs. The last line of the error is Reason: image not found.

The solution is to run the following command on the terminal:

$ Sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18.dylib

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

Test

Run the following command to test:

$ cd ~$ pythonPython 2.5.1 (r251:54863, Apr 15 2008, 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 will be a hard error (cannot be downgraded to a warning) in the future

It has been verified on the Internet: http://www.tuicool.com/articles/zi7vzu. it seems that Xcode of Mac OS treats unknown parameters as error from 5.1 to the compiler. We need to use ARCHFLAGS to downgrade the error to warning, so the installation command should be as follows:

 

Sudo ARCHFLAGS =-Wno-error = unused-command-line-argument-hard-error-in-future python setup. py build


Detailed configuration process of django131 + mysql (setting has been written as django ...... Mysql)

In settings. py, the mysql account and password must be correctly configured.
 
When python is connected to mysql on mac

It should be a version issue. If you have programming experience. You can compile the source code by yourself.

Delete the original version first.

There is another way. Install mysql on your own, and overwrite mysql. so in the existing python directory.

It may succeed.

If not, Delete the existing version and try to install another version. The old version may work, or the new version may work.

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.