Create a new mysql.py and write the following code:
| The code is as follows |
Copy Code |
| Import MySQLdb |
After the operation found Importerror:no module named MySQLdb, that your Python environment is not installed MYSQLDB This module, then go to install Bai, do not install does not matter, one installation of various problems AH.
First I use the command pip install Mysql-python, a wait, throw an "error can not find Mysql_config", I said no ability to change this error, a search to determine their own source code compiled installation.
First go to this site under http://sourceforge.net/projects/mysql-python/, after the good after the direct decompression. Then run the sudo python setup.py build and report a mistake IOERROR:CRC check failed, which Nima what the error is. Have not encountered the error, but also a search, someone suggested that there may be a compression error. I just thought I was a Mac, maybe it's a problem, run the command
| The code is as follows |
Copy Code |
TAR-ZXVF mysql-xx.tar.gz. CD./mysql-xx sudo python setup.py build |
It's finally done.
But mistakes always follow an unprepared person to report the error can not find mysql_config with PHP install reported the same mistake, with the source code we can change it, and finally a brother search the setup_posix.py put inside the
| The code is as follows |
Copy Code |
| Mysql_config.path = "Mysql_config" #改为 the mysql_config path of the local computer |
Continue to the next step Python setup.py build, OK finally perfect, then go to run mysql.py error again, this tip
Reason:image not found, all right, we have to go to the search, the problem is easy to solve, direct Run command
| The code is as follows |
Copy Code |
| sudo ln-s/usr/local/mysql/lib/libmysqlclient.18.dylib/usr/lib/libmysqlclient.18.dylib |
Well, finally, I can use it, tears running.
PS: Run the command or add a sudo, otherwise there will be some unknown problems.