


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 build
mysql_config not found
mysql_config.path = "mysql_config"
whereis mysql
sudo apt-get install libmysqlclient-dev
file -name mysql_config
Error message :
error: command 'i686-linux-gnu-gcc' failed with exit status 1
sudo apt-get install python-dev
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. .- The first one is if steuptools is not installed, an error will be reported during the third step of compilation
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.
- The second one is about the error reported in the python.h file. This is a problem with the python version. The python version needs to be dealt with, so I won’t say more.
- The third one is the /usr/bin/ld:cannot find -lmysqlclient_r error, which is due to the
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

Golang is more suitable for high concurrency tasks, while Python has more advantages in flexibility. 1.Golang efficiently handles concurrency through goroutine and channel. 2. Python relies on threading and asyncio, which is affected by GIL, but provides multiple concurrency methods. The choice should be based on specific needs.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

Running Python code in Notepad requires the Python executable and NppExec plug-in to be installed. After installing Python and adding PATH to it, configure the command "python" and the parameter "{CURRENT_DIRECTORY}{FILE_NAME}" in the NppExec plug-in to run Python code in Notepad through the shortcut key "F6".

Golang and Python each have their own advantages: Golang is suitable for high performance and concurrent programming, while Python is suitable for data science and web development. Golang is known for its concurrency model and efficient performance, while Python is known for its concise syntax and rich library ecosystem.

Although Notepad cannot run Java code directly, it can be achieved by using other tools: using the command line compiler (javac) to generate a bytecode file (filename.class). Use the Java interpreter (java) to interpret bytecode, execute the code, and output the result.

Python is highly favored for its simplicity and power, suitable for all needs from beginners to advanced developers. Its versatility is reflected in: 1) Easy to learn and use, simple syntax; 2) Rich libraries and frameworks, such as NumPy, Pandas, etc.; 3) Cross-platform support, which can be run on a variety of operating systems; 4) Suitable for scripting and automation tasks to improve work efficiency.

ChooseGolangforhighperformanceandconcurrency,idealforbackendservicesandnetworkprogramming;selectPythonforrapiddevelopment,datascience,andmachinelearningduetoitsversatilityandextensivelibraries.
