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 ~