Modulenotfounderror No module named 'mysql' in Python

533 views 10 slides Jun 19, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

mysql module not found is an error that occurs in python. It appears like ModuleNotError: No module named 'mysql.' This error occurs when you forget to install a module called mysql-connector-python in a preferable environment.

https://bit.ly/3RaJ0ro


Slide Content

No module named ‘mysql’
in Python
www.tutorialandexample.com
MODULENOT
FOUNDERROR

INTRODUCTION
One common reason for this error is that
the MySQL module is not installed on
your system. Try importing the module in
a Python script to check if this is the case.
If the module is not installed, the
interpreter will raise the
“ModuleNotFoundError.”

MYSQL PYTHON : ABOUT MYSQL
•MySQL is a fast, easy-to-use relational database. It is currently the most
popular open-source database
•MySQL is used for many small and big businesses. It is developed,
marketed, and supported by MySQL AB, a Swedish company. It is written in C
and C++.
•MySQL is an open-source database, so you don’t have to pay a single
penny to use it. MySQL Features
•MySQL is a fast, easy-to-use relational database.
•MySQL is used for many small and big businesses.
•MySQL is an open-source database, so you don’t have to pay.

MySQL module not found is an error that
occurs in Python. This error occurs when you
forget to install a module called mysql-
connector-python in a preferable
environment.
ModuleNotError:
No module named
'mysql.'

To fix this error, we install a new module by using a command
called
pip install mysql-connector-python
If this error occurs, you have to open the project's root directory and
install the module by using the above command. This command
only works in a virtual environment. Or by using Python 2.

pip3 install mysql-connector-python
For Python 3, use the command
below:

By installing this module, sometimes you might get a permission error. To fix that, we
use the command below
sudo pip3 install mysql-connector-python
sometimes you won't get pip in the PATH environment variable then we use the bellow
command to fix that error
python -m pip install mysql-connector-python
if you get the same error while working in python 3, then we use the below
command for it
python3 -m pip install mysql-connector-python
for anaconda, we use the below command
conda install -c anaconda mysql-connector-python

After installing the mysql-connector-python, we have to import that again in the code
to use it. For example, let us see an example code:
import mysql.connector
# Connect to server
cnx = mysql.connector.connect(
host="127.0.0.1",
port=3305,
user="andy",
password="$unrise_123")
# Get a cursor
cur = cnx.cursor()
# Execute a query
cur.execute("SELECT CURDATE()")
# Fetch one result
row = cur.fetchone()
print("Current date is: {0}".format(row[0]))
# Close connection'
cnx.close()
Output:
Current date is: {0}

Not having the pre-installed package mysql-connector-python we can -install
it by using the pip install mysql-connector-python.
If you install the package of another version without checking the version of
your system, an error occurs
Whenever we install the package worldwide, we must use the virtual
environment, or an error occurs.
If the Python version of the IDE you are working on, you will get an error.
If you cover the name of the official module by naming the nodule mysql.py
Anytime you use a module name as a variable name, the variable name will
import the variable.
Few reasons for the error
ModuleNotFoundError

THANK
YOU VERY
MUCH!
PRESENTED BY JAVATPOINT
www.tutorialandexample.com