Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ModuleNotFoundError: No module named 'MySQLdb'

After finishing of one of my Flask projects, I uploaded it on github just like everybody else. after a 2-3 months period I downloaded the entire githube repository on another machine to run it. However, the app is not working because the packages are not found giving the following message

ModuleNotFoundError: No module named 'Flask'

So I ended up downloading all packages starting from Flask, SQLalchemy,..etc! but I got stuck with MySQLdb:

(MYAPPENV) C:\Users\hp\myapp>python run.py
Traceback (most recent call last):
  File "run.py", line 1, in <module>
    from app import app
  File "C:\Users\hp\myapp\app\__init__.py", line 4, in <module>
    from instance.config import engine
  File "C:\Users\hp\myapp\instance\config.py", line 52, in <module>
    engine = create_engine("mysql://root:root@localhost/MYAPPDB")
  File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\__init__.py", line 425, in create_engine
return strategy.create(*args, **kwargs)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\engine\strategies.py", line 81, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
  File "C:\Users\hp\AppData\Local\Programs\Python\Python37-32\lib\site-packages\sqlalchemy\dialects\mysql\mysqldb.py", line 102, in dbapi
    return __import__('MySQLdb')
ModuleNotFoundError: No module named 'MySQLdb'

Could anybody please help with this issue? I am using python37 on windows machine. I even tried downloading packages such as mysqlclient,..etc but it didn't work out.

like image 627
Belle Avatar asked Oct 27 '18 18:10

Belle


People also ask

What is MySQLdb in Python?

What is MYSQLdb? MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API.


2 Answers

I have read that mysqldb is not supported by python3

And it looks like when you are trying to connect to your database you are using mysql db to connect to the database by default!

you need to change it by editing your DATABASE_URI configuration

But before you need to install the connector extension :

with this command :

pip install mysql-connector-python

And according to this documentation you can edit your DATABASE_URI and change the default connector like this :

DATABSE_URI='mysql+mysqlconnector://{user}:{password}@{server}/{database}'.format(user='your_user', password='password', server='localhost', database='dname')

I hope this will help...

like image 151
Espoir Murhabazi Avatar answered Sep 28 '22 02:09

Espoir Murhabazi


You can install mysqlclient with pip

If using Python3, try this:

pip3 install mysqlclient

or in Python2

pip install mysqlclient

like image 17
Tri Avatar answered Sep 29 '22 02:09

Tri