Run the following command directly
sudo pip install Mysql-python
Report the following error
[Email protected]:~$ sudo pip install mysql-pythondownloading/unpacking mysql-python downloading MySQL-python-1.2.5. zip (108kB): 108kB downloaded Running setup.py (path:/tmp/pip_build_root/mysql-python/setup.py) Egg_info forPackage mysql-python sh:1:mysql_config: notfound Traceback (most recent): File"<string>", line 17,inch<module>File"/tmp/pip_build_root/mysql-python/setup.py", line 17,inch<module>metadata, Options=get_config () File"setup_posix.py", line 43,inchGet_config Libs= Mysql_config ("Libs_r") File"setup_posix.py", line 25,inchMysql_configRaiseEnvironmentError ("%s not found"%(Mysql_config.path,)) Environmenterror:mysql_config notfound complete output fromcommand python setup.py egg_info:sh:1:mysql_config: notFound
Solutions are:
Installing Python-dev
sudo apt-get install Python-dev
And then install
sudo apt-get install Libmysqlclient-dev
Final installation
sudo pip install Mysql-python
This will be a success.
Here is the test code:
ImportMySQLdbTry: Conn= MySQLdb.connect (host='127.0.0.1', user='Root', passwd='Root', db='MyDB', port=3306) cur=conn.cursor () Cur.execute ('INSERT into test values (0, "x0")') Conn.commit () Cur.close () Conn.close ( )Print "Finish Insert Direct"exceptmysqldb.error,e:PrintE.ARGS[1]
Python Module Mysql-python installation (under Ubuntu System)