Python MYSQLdb module installation in linux environment, pythonmysqldb

Source: Internet
Author: User

Python MYSQLdb module installation in linux environment, pythonmysqldb

After learning about python database programming, I learned the basic concepts and planned to get started with the experiment. I got stuck in the installation of the MYSQLdb package, and it took me half a day to solve the problem. Record the problems I encountered when installing this package in linux. The system is ipvtn15.04.


1. Download

The first problem is that the module installation function of pycharm Project Interpreter cannot automatically download and install the MYSQLdb package.

Error occurred when installling package

There is no way, so you have to download it manually. Download the MYSQLdb package for linux:

Http://sourceforge.net/projects/mysql-python/file/mysql-python/

Select the version you want to install on the page to download. the version I downloaded is 1.2.4b4.


2. Installation

1. After the download, open the terminal and switch to your own download file directory, which is/home/hai/download on my computer. Then decompress the downloaded file, that is, enter:

Tar xfz MySQL-python-1.2.4b4.tar.gz

Ii. Use commands

Cd MySQL-python-1.2.4b4

Switch to the decompressed directory.


3. Compile the MYSQLdb package

Enter the command

Python setup. py build


The error message is

Mysql_config not found

After google finds that you want to modify MYSQLdb and decompress it, The setup_posix.py 26th line in the directory is

Mysql_config.path = "mysql_config"

Mysql_config is the name of a file in the mysql installation directory. You need to change the value of 26 rows of variables to the absolute path of this file.

Therefore

Whereis mysql

View the database installation directory and go to the installation directory. However, the installation directory does not contain the mysql_config file.

Continue to google and find that libmysqlclient-dev is not installed. then install it! Run the following command:

Sudo apt-get install libmysqlclient-dev

Install this item and run the following command:

File-name mysql_config

Check the file path. OK.

Modify the setup_posix.py file, and then use the python setup-python-1.2.4b4 installation, and encountered a problem, error message:

Error: command 'i686-linux-gnu-gcc 'failed with exit status 1

Ah, ah.

Continue to google. If python-dev is not installed, install it. Run the following command:

Sudo apt-get install python-dev

After the installation is complete, run the python setup. py build command N times.

4. Run the sudo python setup. py install command.

Well, I finally installed it. Experiment in python and import the MYSQLdb module, import MYSQLdb, no message. Well, no message is the best message. The installation is successful!


P.S. In addition, I also saw several Error alerts during the google process. Although I have not encountered them, I 'd like to mention them here.
First, if steuptools is not installed, the ImportError: No module named setuptools error will be reported during step 3 Compilation. Then, install setuptools. As for the installation of setuptools, this is another problem, I will not go into detail.
The second is about the python. h file error. This is a problem with the python version. You need to deal with the python version.
The third error is/usr/bin/ld: cannot find-lmysqlclient_r. This is because the configuration file does not take effect. Find the mysql configuration file and use the: ldconfig command to refresh and make it take effect.

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.