How To Install Pymysql In Python?
Last Updated :
30 Jan, 2024
We want to connect our Python program to MySQL to execute our MySQL query to get some data from our MySQL database. We can achieve this easily by using the PyMySQL Python library. In this article, let us look at what PyMySQL is, its features, and how to install it using the pip package manager.
What is PyMySQL in Python?
The PyMySQL library in Python is one of the popular Python libraries. PyMySQL is a lightweight and pure Python-based MySQL client library. It allows your Python program to connect to the MySQL database and interact with it by executing the query from your Python program to manage your data. This library is typically useful when working on automation programs that involve MySQL databases for storing and retrieving data or even when working on data analysis tasks where your data is stored in a central store using MySQL, etc.
Features of PyMySQL in Python
- Pure Python Implementation: It is easy to install and doesn't need any other external libraries or dependencies.
- Support for MySQL and MariaDB: PyMySQL library provides support for MySQL and MariaDB databases.
- Compatibility: It is compatible with the Python 3.x version. It can be viewed as a good alternative for MySQL-Python library as MySQL-Python library does not support Python 3.x version.
Why use PyMySQL?
PyMySQL library is a pure Python MySQL driver that is lightweight and easy to use, and that provides support for the Python 3.x version. It can be installed using the pip package manager and does not have any other external dependencies. Also, it is entirely open-source and hosted on Github, so you can peek into the source code of this library. It is released on PyPI.
Install PyMySQL in Python
You can use pip, which is a Python package manager, to install the pymysql library. In this article, we will cover the installation of the PyMySQL library in Windows as well as Linux:
- Install PyMySQL on Windows
- Install PyMySQL on Linux
Install PyMySQL on Windows
Below are some steps by which we can install PyMySQL in windows in Python:
Step 1: Open Command Prompt
Open Command Prompt on your Windows operating system.
Step 2: Install pymysql
Type the below command in the cmd you have opened:
pip install pymysql
Install pymysql using pip.If the above command throws an error, then type the below command:
python -m pip install pymysql
Install pymysql using python pipIt will take a few seconds to install. Wait for some time for the installation to finish. Now, you have successfully installed pymysql on your Windows system.
Step 3: Verify Installation
You can verify whether the installation was successful, open a Python shell, and try importing the library. If the import statement runs without any error, it means your installation was successful.
Verify pymysql installationInstall PyMySQL on Linux
Below are some steps by which we can install PyMySQL in linux in Python:
Step 1: Open Terminal
Open the Linux Terminal on your Linux machine.
Step 2: Install pymysql
Type the below command in the terminal you have opened:
pip3 install pymysql
Install pymysql using pip3If the above command doesn't work, then run the below command:
python -m pip install pymysql
Install pymysql using python-pipIt will take a few seconds to install. Wait for some time for the installation to finish. Now, you have successfully installed pymysql on your Linux system.
Step 3: Verify Installation
You can verify whether the installation was successful, open a Python shell, and try importing the library. If the import statement runs without any error, it means your installation was successful.
Verify pymysql installation
Similar Reads
Install Coverage in Python
Understanding the execution of code, during testing is vital in software development. Code coverage plays a role in providing insights to developers regarding the portions of their code that are executed. By identifying areas of code that have not been tested developers can improve the quality and r
2 min read
Install Psycopg2 using PIP in Python
In this article, we will guide you through the process of installing Psycopg2 with "Pip" on Python. Psycopg2 is a popular PostgreSQL adapter for the Python programming language, allowing Python programs to interact with PostgreSQL databases. What is Psycopg2?Psycopg2 is a PostgreSQL adapter for the
2 min read
Install Poetry to Manage Python Dependencies
Poetry is a modern and user-friendly dependency management tool for Python. It simplifies the process of managing project dependencies, packaging, and publishing. In this article, we will see how to install poetry in Python in Windows. What is Python Poetry?Python Poetry is a modern and comprehensiv
2 min read
How To Install Sqlalchemy-Continuum
In this article, we will guide you through the process of installing Sqlalchemy-Continuum. What is Sqlalchemy-Continuum?Sqlalchemy-Continuum is an extension for SQLAlchemy, a popular SQL toolkit and Object-Relational Mapping (ORM) library for Python. The purpose of Sqlalchemy-Continuum is to provide
1 min read
How To Install A Package Inside Virtualenv?
Understanding the significance of a virtual environment in Python is crucial before exploring package installation in virtualenv. It provides a segregated workspace for projects, isolating dependencies and ensuring the system-installed Python remains unaffected. This isolation enables seamless switc
3 min read
Pipx : Python CLI package tool
In this article, we will explore the basics of pipx python CLI package tool. Pipx is a tool in Python that allows us to run python packages that have a CLI interface in the global context of your system. It uses its own environment for managing the packages. Here, we will cover its installations, se
4 min read
Install Flask-Sqlalchemy with Pip
Flask is a Python-based web app framework that helps you develop lightweight and deployable web apps. The Flask framework supports several features like URLs, Templating Engines, and Routing. To provide support for database connection and query, one can use the Flask-Sqlalchemy library in Python, wh
3 min read
Installing Sqlalchemy-Utils using Python Pip
In this article, we will explore how to Install Sqlalchemy-Utils Using Pip. To utilize Sqlalchemy-Utils functionalities, it is essential to Install Sqlalchemy-Utils Using Pip and this can be achieved by following the steps outlined below. What is Sqlalchemy-Utils ?SQLAlchemy-Utils is a library that
2 min read
Install the Latest Version of Pytest
In the Python environment, we have various libraries to make applications and feature-based projects. Pytest is the testing framework for Python which mainly simplifies the process of writing and executing the unit tests for the application. The Pytest library uses the easy-to-read syntax for writin
3 min read
No Module Named Sqlalchemy-Utils in Python
In Python Programming, when working with various modules and inbuilt packages, we always face and encounter the error of No Module Named 'Sqlalchemy-Utils. In this article, we are going to see how we can fix the Python Code Error: No Module Named 'Sqlalchemy-Utils'. This error is encountered when th
3 min read