It was a permissions issue, in my venv directory, some libraries were installed by the user that runs the program (runcloud), and others were installed by root. For example:
drwxrwxr-x+ 3 runcloud runcloud 4096 Nov 22 17:02 jinja2
drwxrwxr-x+ 3 runcloud runcloud 4096 Nov 22 17:02 jiter
drwxr-xr-x+ 4 root root 4096 Dec 5 20:21 mariadb
drwxrwxr-x+ 3 runcloud runcloud 4096 Nov 22 17:02 markupsafe
drwxr-xr-x+ 24 root root 4096 Dec 5 19:06 numpy
This allowed the python program to recognize the folders (and import the libraries) but it couldn't access anything inside of them. Hence the missing attribute error.
To fix the issue I went through each library installed by root, and copied the permissions and ownership from one of the functional libraries (flask).
Here's an example for mariadb:
chmod -R --reference=flask mariadb
chown -R --reference=flask mariadb
After this the program could import the libraries and access the files inside without any issues.