Installation method of MySQLdb module in python under linux environment

  • 2020-06-03 07:10:58
  • OfStack


Recently, I started to learn python database programming. When I got to know the basic concepts and decided to try out experiment 1, I got stuck in the installation of MYSQLdb package and struggled for a long time to solve it. Note 1 The problems I encountered installing this package in linux.

The system is ubuntn15.04.

1. Download

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

Error occurred when installling package

I have no choice but to download it manually. MYSQLdb package linux system download address is: http: / / sourceforge net/projects/mysql - python/file/mysql python /

Select the version you want to install in the page and download it. The version I downloaded is 1.2.4b4

2. Install

1: After downloading, open the terminal and switch to the directory of downloaded files. In my computer, it is directory /home/hai/download. Then unzip the downloaded files and input them in the terminal:

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

2: Use commands

cd MySQL-python-1.2.4b4

Switch to the unzipped directory.

3: Compile the MYSQLdb package

Type the command

python build

When you encounter a problem, the error message is

mysql_config not found

After google, I found that I wanted to modify line 26 of in the MYSQLdb unzipped directory. This line is

mysql_config.path = "mysql_config"

mysql_config is the name of one file in the mysql installation directory, and you need to change the value of the 26 line variable to the absolute path of the file.

So using

whereis mysql

View the database installation directory, enter the installation directory. But found no mysql_config file in the installation directory, ah, angry ah.

Continue to google and find that ES79en-ES80en is not installed, then install! Use the command:

sudo apt-get install libmysqlclient-dev

Install this thing and then use the command:

file -name mysql_config

Look at the path to this file, ok, and there you have it.

After modifying the setup_ES91en. py file, and then using python ES94en-ES95en-1.2.4 b4 installation, we have encountered another problem, error message:

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


Continue with google, es103EN-ES104en is not installed, ok, then install. Use the command:

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

After the installation is complete, the N command is used again python build Ok, finally no error, now just 1 step to install successfully.

4: Enter the command sudo python setup. py install

Ok, finally installed, in python experiment 1, import 1 MYSQLdb module, import MYSQLdb No message, well, no message is the best message, installation successful!


In addition, in the process of google, I also saw several error alarms. Although I did not encounter them, I still mention 1 here.

The first is that if steuptools is not installed, an error will be reported in step 3 compilation ImportError: No module named setuptools , then install setuptools. As for the installation of setuptools, that is another problem, I will not say more. The second one is about the error of ES134en.h file, which is the version of python. I need to deal with the version of python under 1, and I won't say more. Third is/usr/bin/ld: cannot find - lmysqlclient_r error, this is due to the configuration file is not effective. Find the mysql configuration file and use it :ldconfig Command refresh for it to take effect.


Related articles: