How do I connect to MySQL from Flask?

I’m learning Python and Flask, and I have a problem. I have created a project and added a requirements.txt file that has these contents:


When I start Devilbox, I see in the logs that either it downloads the needed modules or they are already installed:

[INFO] Installing pip requirements from: /shared/httpd/compartidor/requirements.txt
Requirement already satisfied: mysql-connector-python in ./venv/lib/python3.8/site-packages (from -r /shared/httpd/compartidor/requirements.txt (line 1)) (8.3.0)
Requirement already satisfied: datetime in ./venv/lib/python3.8/site-packages (from -r /shared/httpd/compartidor/requirements.txt (line 2)) (5.4)
Requirement already satisfied: zope.interface in ./venv/lib/python3.8/site-packages (from datetime->-r /shared/httpd/compartidor/requirements.txt (line 2)) (6.2)
Requirement already satisfied: pytz in ./venv/lib/python3.8/site-packages (from datetime->-r /shared/httpd/compartidor/requirements.txt (line 2)) (2024.1)
Requirement already satisfied: setuptools in ./venv/lib/python3.8/site-packages (from zope.interface->datetime->-r /shared/httpd/compartidor/requirements.txt (line 2)) (50.3.2)
WARNING: You are using pip version 20.2.4; however, version 24.0 is available.
You should consider upgrading via the '/shared/httpd/compartidor/venv/bin/python -m pip install --upgrade pip' command.
Python 3.8.6
Flask 1.1.2

But then, I try to execute a Python app that starts by importing the MySQL connector, it complains that it can’t find that module. I import them in my Python script this way:

from flask import Flask
from flask import render_template
import mysql.connector

And the error I get is:

flask.cli.NoAppException: While importing "main", an ImportError was raised:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/flask/", line 240, in locate_app
  File "/shared/httpd/compartidor/html/", line 3, in <module>
    import mysql.connector
ModuleNotFoundError: No module named 'mysql'

So what do I do? I should mention that I am using Devilbox v. 1.9.0 (I know, it’s old).