Python MySQLdb Installation notes in Linux, pythonmysqldb

Source: Internet
Author: User

Python MySQLdb Installation notes in Linux, pythonmysqldb

Once in a windows environment at home
See python MySQLdb quick installation and troubleshooting in windows.
Http://www.bkjia.com/article/65746.htm

In the company's development needs, another time, under linux.
I found that it was really painful to install it by compiling, but it was just a matter of time and a variety of problems...

There are two methods:

A. quick installation
B. compile it by yourself

1. The fastest and easiest way (in a hurry)
Copy codeThe Code is as follows:
Sudo yum install MySQL-python

Possible problems:
Copy codeThe Code is as follows:
>>> Import MySQLdb
Traceback (most recent call last ):
File "<stdin>", line 1, in?
File "MySQLdb/_ init _. py", line 22, in?
Raise ImportError ("this is MySQLdb version % s, but _ mysql is version % r" %
ImportError: this is MySQLdb version (1, 2, 3, 'final', 0), but _ mysql is version (1, 2, 1, 'final', 1)

Cause: the previous compilation method is used for installation. The following is 1.2.3, but yum is currently used for a maximum of 1.2.1. Conflict
Solution: delete compiled files
Copy codeThe Code is as follows:
Rm-rf Co., MySQL-python-1.2.3/

Proceed
Copy codeThe Code is as follows:
>>> Import MySQLdb

If no error exists, it indicates the operation is successful.


2. Compile and install it by yourself (if you have time... Token)

Required:
A. gcc
B. setuptools
Copy codeThe Code is as follows:
Wget-O setuptools-0.6c8.tar.gz http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c8.tar.gz

Decompress and run sudo easy_install.py [or python setup. py build & sudo python setup. py install].
C. python-dev in sudo apt-get install python-dev
Otherwise, an exception occurs: fatal error: Python. h: the file or directory does not exist.

Steps:
A. Download: wget http://sourceforge.net/projects/mysql-python/files/latest/download
B.
Copy codeThe Code is as follows:
$ Tar xfz MySQL-python-1.2.3.tar.gz
$ MySQL-python-1.2.3 cd
$ Whereis mysql_config
Mysql_config:/usr/bin/mysql_config
$ Vim site. cfg

Modify mysql_config to the mysql configuration file path/usr/bin/mysql_config
Also modify
Copy codeThe Code is as follows:
Threadsafe = False
$ Python setup. py build
$ Sudo python setup. py install

End ~

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.