import mysql in python file fails
Scott Kitterman
sklist at kitterman.com
Sat Feb 5 15:12:11 UTC 2022
On Saturday, February 5, 2022 8:54:58 AM EST dy1977--- via Unbound-users
wrote:
> Hello,
>
> I have been using unbound with a python file for years in Debian 10.
>
> I am installing the system in Debian 11 but "import mysql" fails.
>
> mysql.connector was properly installed, and if I run directly the python
> file, it does not provoque any error. Here is the code
>
> import csv, json, time, os, sys
> from collections import OrderedDict
> sys.path.append('/usr/local/lib/python3.9/dist-packages')
> import mysql
> import mysql.connector as database
>
> But when I try to start unbound, the following error happens :
>
> Feb 5 14:24:38 Idefix-APU2 systemd[1]: Starting Unbo
>
> und DNS server...
>
> Feb 5 14:24:38 Idefix-APU2 unbound: [32270:0] notice: init module 0:
> validator
>
> Feb 5 14:24:38 Idefix-APU2 unbound: [32270:0] notice: init module 1: python
>
> Feb 5 14:24:38 Idefix-APU2 unbound[32270]: Traceback (most recent call
> last):
>
> Feb 5 14:24:38 Idefix-APU2 unbound[32270]: File
> "/usr/lib/idefix/unbound-filter.py", line 20, in <module>
>
> Feb 5 14:24:38 Idefix-APU2 unbound[32270]: import mysql
>
> Feb 5 14:24:38 Idefix-APU2 unbound[32270]: ModuleNotFoundError: No
> module named 'mysql'
>
> Feb 5 14:24:38 Idefix-APU2 unbound: [32270:0] error: pythonmod: can't
> parse Python script /usr/lib/idefix/unbound-filter.py
>
> I have updated the sys.path.append to the new python version. In this
> directory there is a 'mysql' subdirectory, and in this subdirectory
> there is a __init__.py file. I do not understand what is missing.
If the module is installed correctly you should not have to manually modify
sys.path. I would look into whatever caused you to consider doing that and
try and address that. That may be your root cause issue.
On Debian systems with the Debian provided python3, /usr/local/lib/python3.X/
dist-packages is already in the system path.
Scott K
More information about the Unbound-users
mailing list