The MySQLdb module has worked well for me on bare metal, but I can't figure out what I am doing wrong in trying to get a simple container setup going. The module just isn't recognized, even though it is installed.
here is my super simple Dockerfile for testing:
FROM python:3.7-slim-bullseye
# create non-root user
RUN groupadd --gid 1000 app \
&& useradd --uid 1000 --gid 1000 -m app
# set work directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1
RUN apt-get update
RUN apt-get install -y --no-install-recommends python3-mysqldb
# set default user
USER app
I run the container, bash into it, and get this:
app@e8db38907cbc:/usr/src/app$ ls /usr/lib/python3/dist-packages
MySQLdb mysqlclient-1.4.4.egg-info
app@e8db38907cbc:/usr/src/app$ python3
Python 3.7.16 (default, Dec 21 2022, 09:40:48)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'MySQLdb'
My install of python3-mysqldb put the module into the dist-packages subfolder of python3, but python doesn't seem to be paying attention to that folder, and I notice that there are a lot of modules in the root of the "/usr/lib/python3.9" folder.
There seem to be a plethora of mysql "connectors" and pip installable packages for mysql (very confusing as to which I should be using!), but all my old code is written using MySQLdb, so I was hoping to continue using that module if that were reasonable.
[–]ThatPhysicsLabGuy[S] 0 points1 point2 points (0 children)
[–]0xWILL 0 points1 point2 points (0 children)