'Apache can't find mysql.connector when running Python cgi

I have a cgi that ran fine on python 2.7.

When I converted it to python3, I had to install some modules again. I installed requests by simply copying it from a 2.7 site-packages directory to /usr/lib/python3.7/site-packages.

I used pip to install mysql.connector, during which the installer said that since the global site-packages directory was not writable, it was installing it in my user directory instead.

The cgi ran fine when I ran it from the command line on the host, but when it is called as a cgi, I get:

    import mysql.connector
ModuleNotFoundError: No module named 'mysql.connector'

So, apache can't find mysql.connector, even though it finds requests and everything else. I tried copying all the mysql* stuff from my local site-packages like I did with requests, but no joy.

Here's where python3 is looking for things when I'm running it as me:

(myusername)lab:/var/www/cgi-bin$ python3 -m site
sys.path = [
    '/var/www/cgi-bin',
    '/usr/lib64/python37.zip',
    '/usr/lib64/python3.7',
    '/usr/lib64/python3.7/lib-dynload',
    '/home/myusername/.local/lib/python3.7/site-packages',
    '/usr/lib64/python3.7/site-packages',
    '/usr/lib/python3.7/site-packages',
]
USER_BASE: '/home/myusername/.local' (exists)
USER_SITE: '/home/myusername/.local/lib/python3.7/site-packages' (exists)
ENABLE_USER_SITE: True

Here's where I think apache is looking for things:

(myusername)lab:/var/www/cgi-bin$ sudo -u apache python3 -m site
sys.path = [
    '/var/www/cgi-bin',
    '/usr/lib64/python37.zip',
    '/usr/lib64/python3.7',
    '/usr/lib64/python3.7/lib-dynload',
    '/usr/lib64/python3.7/site-packages',
    '/usr/lib/python3.7/site-packages',
]
USER_BASE: '/usr/share/httpd/.local' (doesn't exist)
USER_SITE: '/usr/share/httpd/.local/lib/python3.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: True

Any guidance would be greatly appreciated.

Update: I changed permissions for all the mysql* directories and their contents to be readable and executable by everybody, and that got rid of the error. But I don't know if that was the best solution. Seems like it would not be.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source