Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

python - ModuleNotFoundError: No module named 'flask_mysqldb' even if installed

I'm using mysql with flask for developing a basic website and I'm getting ModuleNotFound error even if I have the module installed. Can someone solve this ?

  File "c:/Users/prshi/Desktop/Py files/FLASK app/app.py", line 3, in <module>
    from flask_mysqldb import MySQL
ModuleNotFoundError: No module named 'flask_mysqldb'
PS C:UsersprshiDesktopPy filesFLASK app> pip install flask-mysqldb
Requirement already satisfied: flask-mysqldb in c:python39libsite-packages (0.2.0)
Requirement already satisfied: Flask>=0.10 in c:python39libsite-packages (from flask-mysqldb) (1.1.2)
Requirement already satisfied: mysqlclient in c:python39libsite-packages (from flask-mysqldb) (1.4.6)
Requirement already satisfied: Werkzeug>=0.15 in c:python39libsite-packages (from Flask>=0.10->flask-mysqldb) (1.0.1)
Requirement already satisfied: Jinja2>=2.10.1 in c:python39libsite-packages (from Flask>=0.10->flask-mysqldb) (2.11.2)
Requirement already satisfied: itsdangerous>=0.24 in c:python39libsite-packages (from Flask>=0.10->flask-mysqldb) (1.1.0)
Requirement already satisfied: click>=5.1 in c:python39libsite-packages (from Flask>=0.10->flask-mysqldb) (7.1.2)
Requirement already satisfied: MarkupSafe>=0.23 in c:python39libsite-packages (from Jinja2>=2.10.1->Flask>=0.10->flask-mysqldb) (1.1.1)
PS C:UsersprshiDesktopPy filesFLASK app> 
question from:https://stackoverflow.com/questions/65920135/modulenotfounderror-no-module-named-flask-mysqldb-even-if-installed

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This a common python path issue, to make sure it isn't your case, type :

import sys
print(sys.path)

and check if it contains:

/usr/local/lib64/python3.6/site-packages

The problem is that you install the package using pip somewhere, and you're trying to import it from somewhere else where it's not installed. The trick to solve it is by running this command :

export PYTHONPATH=$PYTHONPATH:/path/to/your/modules 

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...