Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Debian Buster: ModuleNotFoundError: No module named 'mysql'

2,467 views
Skip to first unread message

^Bart

unread,
Jan 18, 2020, 10:44:39 AM1/18/20
to
Hi guys,

I'd like to use Python to connect to my MariaDB db, it works from
phpmyadmin and if I open a console with mysql -u root -p.

I tried:

$ pip search mysql-connector | grep --color mysql-connector-python

mysql-connector-python (8.0.19) - MySQL driver
written in Python
mysql-connector-python-rf (2.2.2) - MySQL driver
written in Python
mysql-connector-python-dd (2.0.2) - MySQL driver
written in Python

$ pip install mysql-connector-python-rf

Requirement already satisfied: mysql-connector-python-rf in
/usr/local/lib/python2.7/dist-packages (2.2.2)

When I try my code (obviously I replaced parameters with mine!):

import mysql.connector

mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="mypwd"
)

print(mydb)

I have:

Traceback (most recent call last):
File "/home/gabriele/Corso_4.0/Python/Test_MySQL2.py", line 1, in
<module>
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
>>>

What could I do to fix this issue?! :\

Thanks!
^Bart

^Bart

unread,
Jan 18, 2020, 11:03:18 AM1/18/20
to
> What could I do to fix this issue?! :\

I understood I have Python 2.7 and Python 3 but I can't install modules
on Python 3... :\

^Bart

Michael Torrie

unread,
Jan 18, 2020, 11:55:07 AM1/18/20
to
pip is probably defaulting to Python 2.7. Try using pip3, or this more
explicit syntax:

python3 -m pip install <module>


^Bart

unread,
Jan 18, 2020, 12:21:13 PM1/18/20
to
> pip is probably defaulting to Python 2.7. Try using pip3, or this more
> explicit syntax:

Now it works!

Python 3.7.3 (default, Apr 3 2019, 05:39:12)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license()" for more information.
>>>
========== RESTART: /home/gabriele/Corso_4.0/Python/Test_MySQL2.py
==========
<mysql.connector.connection.MySQLConnection object at 0x7f20f16799e8>
>>>

I solved the "issue" by:

# aptitude install python3-pip

$ python3 -m pip install mysql-connector

$ python3 -m pip search mysql-connector | grep --color
mysql-connector-python

$ python3 -m pip install mysql-connector-python-rf

# aptitude install python3-mysqldb

^Bart

황병희

unread,
Jan 19, 2020, 5:40:03 AM1/19/20
to
^Bart <gabriel...@hotmail.com> writes:

>> pip is probably defaulting to Python 2.7. Try using pip3, or this more
>> explicit syntax:
>
> Now it works!
>
> Python 3.7.3 (default, Apr 3 2019, 05:39:12)
> [GCC 8.3.0] on linux
> Type "help", "copyright", "credits" or "license()" for more information.
>>>>
> ========== RESTART: /home/gabriele/Corso_4.0/Python/Test_MySQL2.py
> ==========
> <mysql.connector.connection.MySQLConnection object at 0x7f20f16799e8>
>>>>

Wow, what a beautiful Debian-Python ^^^

Sincerely, Linux fan Byung-Hee

--
^고맙습니다 _地平天成_ 감사합니다_^))//

rack...@gmail.com

unread,
May 7, 2020, 7:30:40 AM5/7/20
to
I have the same issue. I use visual code from Ms and the remote debugging over an ssh.
I am able to do all mysql while in the debugger but running on command line does not work.
The DB is logged in as root as this was the only way I could make it work.

pi@raspberrypi:~/blescan/iBeacon-Scanner-$ pip search mysql-connector | grep --color mysql-connector-python
mysql-connector-python (8.0.20) - MySQL driver written in Python
mysql-connector-python-dd (2.0.2) - MySQL driver written in Python
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
pi@raspberrypi:~/blescan/iBeacon-Scanner-$ pip install mysql-connector-python-rf
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: mysql-connector-python-rf in /home/pi/.local/lib/python3.7/site-packages (2.2.2)
pi@raspberrypi:~/blescan/iBeacon-Scanner-$ sudo python3 BeaconClass.py
Traceback (most recent call last): File "BeaconClass.py", line 7, in <module>
import mysql.connector as mariadb ModuleNotFoundError: No module named 'mysql'
pi@raspberrypi:~/blescan/iBeacon-Scanner-$

MRAB

unread,
May 7, 2020, 7:57:14 AM5/7/20
to
I believe that it's "pip" for "python" (Python 2) and "pip3" for
"python3" (Python 3).

Personally, I'd use:

python3 -m pip ...

or:

sudo python3 -m pip ...

instead.

rack...@gmail.com

unread,
May 7, 2020, 3:23:08 PM5/7/20
to
This only happens when on the command line trying to run the python script. it works fine in visual studio code.

Resinstalled all of the packages mentioned above, it keeps saying it is all fine.

What is different in MS debugger?

rack...@gmail.com

unread,
May 7, 2020, 8:59:41 PM5/7/20
to
i have figured it out. When i made the database, i made it with root access. I think i had to do that to make it accessable for a webpage.

i changed to SU and installed this.

pip install mysql-connector-python-rf and the other listed above. dumped out of su then tried it again. it worked.

So, the package installed under my normal login it seems did not have the access that mysql needed for root. hmm.
0 new messages