Home > Article > Backend Development > Introduction to the installation method of MySQLdb module in python in Linux environment
This article mainly introduces you to the installation method of the MySQLdb module in python under the Linux environment. The article introduces you to it in great detail and has certain reference learning value for your study or work. Friends who need it can come and take a look below.
Preface
After recently starting to learn python database programming, after understanding the basic concepts, I planned to try it out , I got stuck on the installation of the MYSQLdb package, and it took me a long time to solve it. Record the problems I encountered when installing this package in Linux.
The system is ubuntn15.04.
1. Download
The first problem is that Project Interpreter, the module installation function of pycharm software, cannot automatically download and install the MYSQLdb package, displaying
Error occurred when installling package
There is no other way, so I have to download it manually. The download address for the MYSQLdb package for Linux systems is: http://sourceforge.net/projects/mysql-python/file/mysql-python/
Just select the version you want to install on the page and download it. The version I downloaded is 1.2.4b4
2. Installation
1: After downloading, open the terminal and switch to your own Download the file directory, on my computer it is the directory /home/hai/download, then unzip the downloaded file, that is, enter in the terminal:
tar xfz MySQL-python-1.2.4b4.tar.gz
2: Use the command
cd MySQL-python-1.2.4b4
to switch to the decompressed directory.
Three: Compile MYSQLdb package
Enter the command
##
python setup.py buildAt this time, a problem is encountered and the error message is
mysql_config not foundAfter google, I found that I need to modify line 26 of setup_posix.py in the directory after decompressing MYSQLdb. The content of this line 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 the variable on line 26 to the absolute path of this file. So use
whereis mysqlto view the database installation directory and enter the installation directory. But I found that there is no mysql_config file in the installation directory. Ah, I am so angry. Continue to google and find that libmysqlclient-dev is not installed, then install it! Use the command:
sudo apt-get install libmysqlclient-devto install this thing, and then use the command:
file -name mysql_configto view the path of this file, ok , yes. After modifying the setup_posix.py file, and then using python setup-python-1.2.4b4 to install it, I encountered another problem,
Error message :
error: command 'i686-linux-gnu-gcc' failed with exit status 1Ahhhh. Continue to google, it turns out that python-dev is not installed, okay, then install it. Use the command:
sudo apt-get install python-devAfter the installation is completed, use the input After executing the command
python setup.py build N times, OK, finally no error was reported, and now the installation is just one step away from success.
Four: Enter the command sudo python setup.py install
Okay, finally installed, try it in python, import the MYSQLdb module,import MYSQLdb, no message, well, no message is the best news, the installation is successful!
P.S
In addition, during the google process, I also saw several error alarms. Although I have not encountered them, I still mention them here. .ImportError: No module<a href="http://www.php.cn/code/8212.html" target="_blank"> named setuptools</a> , then install setuptools. As for the installation of setuptools, that is another problem, so I won’t go into details.
configuration file not taking effect. Find the mysql configuration file and refresh it using the :ldconfig command to make it effective.
Summarize
The above is the detailed content of Introduction to the installation method of MySQLdb module in python in Linux environment. For more information, please follow other related articles on the PHP Chinese website!