[Problem description] ImportError No module named MySQLdb problem solving, importerrormysqldb
1. Check whether the MySQLdb module has been installed.
Go to the python command line and enter import MySQLdb. If no error is reported, it indicates that this module has been installed. Otherwise, we need to perform several operations.
2. Install and download MySQL for Python
The URL for MySQL for Python is http://sourceforge.net/projects/mysql-python/. you can download the latest installation package and run the following command:
<span style="font-size:12px;">wget http://sourceforge.net/projects/mysql-python/files/latest/downloadtar -xvzf MySQL-python-1.2.4b4.tar.gzcd MySQL-python-1.2.4b4python setup.py buildpython setup.py install</span>
If the error "EnvironmentError: mysql_config not found" is reported when you run python setup. py build, perform the following operations:
Run the whereis mysql_config command. If the following result is displayed, We need to install other things:
My mySQL is installed in the default path of the system.
At this time, we are installing dev
Apt-get install libmysqlclient15-dev
Run whereis mysql_config once.
Modify the MySQL-python-1.2.4b4/site. cfg file, remove the mysql_config = XXX annotation, and change it to mysql_config =/usr/bin/mysql_config
Go back to the MySQLdb source code directory, vi setup_posix.py or vimsetup_posix.py, open the configuration file, find mysql_config.path, and change the path to the bin directory under the mysql installation path, mysql_config.path = "/usr/local/mysql/bin/mysql_config"
Run the following command:
Python setup. py build
Python setup. py install