Install Mysql module MySQLdb in Python

Source: Internet
Author: User

By default, the MySQLdb package is not installed. Do not believe it? You can see the code similar to the following.
Copy codeThe Code is as follows:-bash-3.2 #/usr/local/python2.7.3/bin/python get_cnblogs_news.py
Traceback (most recent call last ):
File "get_cnblogs_news.py", line 9, in <module>
Import MySQLdb
ImportError: No module named MySQLdb
In this case, we have to install the MySQLdb package. The installation procedure is as follows:
1. Download MySQL for Python
Address: http://sourceforge.net/projects/mysql-python/files/mysql-python/
I installed version 1.2.3 here.
Copy codeThe Code is as follows: wget http://sourceforge.net/projects/mysql-python/files/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz
2. Decompress
Copy codeThe Code is as follows: tar zxvf MySQL-python-1.2.3.tar.gz
3. Installation
Copy codeThe Code is as follows: $ cd MySQL-python-1.2.3
$ Python setup. py build
$ Python setup. py install
Note:
If the following error occurs during execution: python setup. py build:
Copy codeThe Code is as follows: EnvironmentError: mysql_config not found
First, find the location of mysql_config, and use
Find/-name mysql_config, for example, in/usr/local/mysql/bin/mysql_config
Modify the setup_posix.py file in 26 rows:
Modify mysql_config.path = "mysql_config":
Copy codeThe Code is as follows: mysql_config.path = "/usr/local/mysql/bin/mysql_config"
Save and run the following command again:
Copy codeThe Code is as follows: python setup. py build
Python setup. py install
OK. This is all done.

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.