[Problem description] ImportError No module named MySQLdb problem solving, importerrormysqldb

Source: Internet
Author: User

[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






Related Article

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.