Home Backend Development Python Tutorial Introduction to the installation method of MySQLdb module in python in Linux environment

Introduction to the installation method of MySQLdb module in python in Linux environment

Jun 18, 2017 am 11:25 AM
linux python module 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
Copy after login

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
Copy after login

2: Use the command


cd MySQL-python-1.2.4b4
Copy after login

to switch to the decompressed directory.

Three: Compile MYSQLdb package

Enter the command


##

python setup.py build
Copy after login

At this time, a problem is encountered and the error message is


mysql_config not found
Copy after login

After 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"
Copy after login

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 mysql
Copy after login

to 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-dev
Copy after login

to install this thing, and then use the command:


file -name mysql_config
Copy after login

to 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 1
Copy after login

Ahhhh.

Continue to google, it turns out that python-dev is not installed, okay, then install it. Use the command:


sudo apt-get install python-dev
Copy after login
After 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. .


  • 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1661
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

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.

Choosing Between PHP and Python: A Guide Choosing Between PHP and Python: A Guide Apr 18, 2025 am 12:24 AM

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.

Linux Architecture: Unveiling the 5 Basic Components Linux Architecture: Unveiling the 5 Basic Components Apr 20, 2025 am 12:04 AM

The five basic components of the Linux system are: 1. Kernel, 2. System library, 3. System utilities, 4. Graphical user interface, 5. Applications. The kernel manages hardware resources, the system library provides precompiled functions, system utilities are used for system management, the GUI provides visual interaction, and applications use these components to implement functions.

PHP and Python: A Deep Dive into Their History PHP and Python: A Deep Dive into Their History Apr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

How to check the warehouse address of git How to check the warehouse address of git Apr 17, 2025 pm 01:54 PM

To view the Git repository address, perform the following steps: 1. Open the command line and navigate to the repository directory; 2. Run the "git remote -v" command; 3. View the repository name in the output and its corresponding address.

Golang vs. Python: Performance and Scalability Golang vs. Python: Performance and Scalability Apr 19, 2025 am 12:18 AM

Golang is better than Python in terms of performance and scalability. 1) Golang's compilation-type characteristics and efficient concurrency model make it perform well in high concurrency scenarios. 2) Python, as an interpreted language, executes slowly, but can optimize performance through tools such as Cython.

Python vs. C  : Learning Curves and Ease of Use Python vs. C : Learning Curves and Ease of Use Apr 19, 2025 am 12:20 AM

Python is easier to learn and use, while C is more powerful but complex. 1. Python syntax is concise and suitable for beginners. Dynamic typing and automatic memory management make it easy to use, but may cause runtime errors. 2.C provides low-level control and advanced features, suitable for high-performance applications, but has a high learning threshold and requires manual memory and type safety management.

laravel installation code laravel installation code Apr 18, 2025 pm 12:30 PM

To install Laravel, follow these steps in sequence: Install Composer (for macOS/Linux and Windows) Install Laravel Installer Create a new project Start Service Access Application (URL: http://127.0.0.1:8000) Set up the database connection (if required)

See all articles