Forums

mysqlDB

Hi There

I have a very quick question, that seems a bit odd:

If I run my web app, it returns the error-

from flask_mysqldb import MySQL
ModuleNotFoundError: No module named 'flask_mysqldb

However, the module must be working because I'm using it to access the database.

Kind regards

Paul

Make sure that your web app is set up to use the same Python version / virtual environment, where you installed the missing package.

Hello

I did do that, but it seems fine - the site is running on python 3.7 and I installed MySQL-python in the bash console using pip3.7 install --user MySQL-python.

However, I still have the same problem.

I thought it was odd that the module has a different name. But that's what google said to do :)

Kind regards

Paul

What do you see when you run pip3.7 show MySQL-python in Bash console? Also, are you sure that the installation was successfull? Not sure if that package supports Python > 3.

University of Michigan SQl "Class": Attempting the "slass" with "Prof" Severence online at U-Mich - and the "class" relies upon the ability to cut-and-paste into the Bash command line... but the paste function appears disabled on this website.

Does this site no longer support that class - and if you do - are there any workarounds that you can suggest.

Love your work - but not so impressed by UMich on Coursera right now... Humble exUK worker, now in Canada

What makes you think the paste functionality does not work? Which keyboard shortcut are you using? Have you tried in a different browser?

Hello again,

I've been totally distracted by other stuff, but I've just come back to this, because it's still confusing/worrying me a little.

Just to recap if I run my app in the console it comes up with an error saying it can't find the module (flask_mysqldb), but everything works fine. The app is using python 3.7.

A bit of my code is below (missing the login stuff, etc...):-

import os
from flask import Flask, request, send_file, jsonify, render_template, url_for, redirect
import jwt
import datetime
from functools import wraps
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
import paho.mqtt.publish as publish
from flask_mysqldb import MySQL
import glob


app = Flask(__name__)
app.config['SECRET_KEY'] = 
app.config['MYSQL_USER'] = 
app.config['MYSQL_PASSWORD'] = 
app.config['MYSQL_HOST'] = 
app.config['MYSQL_DB'] = 
app.config['MYSQL_CURSORCLASS'] = 'DictCursor'

mysql = MySQL(app)
auth = HTTPBasicAuth()

# - create DB entry for new device ------------------------------------------
@app.route("/create_user_credentials",  methods=['GET', 'POST'])
@token_required
def insert_user_credentials():
cur = mysql.connection.cursor()

unique_ID = request.args.get('unique_ID')
password = request.args.get('password')
PT_address = request.args.get('PT_address')

sql_query = '''INSERT INTO customer_info (unique_ID, password, PT_address) VALUES (%s, %s,%s)'''
cur.execute(sql_query, (unique_ID,password,PT_address,))

mysql.connection.commit()
return "200 - user created successfully"

cur.close()
mysql.connection.close()
 # ----------------------------------------------------------------------------

I'm sure its obvious, but if it can't find the module, how is it working?!

Kind regards

Paul

If you run that in a console it will not do anything whether it has an import error or not. So it's definitely not working when you run it in the console.

Hi there

Maybe I used the wrong word, I mean that is a section of the web_app.py file.

And occasionally I click run in the editor to make sure there are no errors importing the various modules.

This is when I get the error.

Kind regards

Paul

Hi again

Ok, I've just realised what the problem is - if I open a python 3.7 console and try-

from flask_mysqldb import MySQL

it works fine

But the default console that opens if you click run in the editor is python 3.9.

Is there anyway to change this to run 3.7

Kind regards

Paul

P.S. sorry for quite so many questions about the same thing

Yes, you can change your default python version from the "System image" tab on your Account page.

Brilliant, thank you v much, have changed it and all is good:)