I'm trying to run a simple Python code on IDLE on Mac (Python3) , but
Traceback (most recent call last):
File "/Users/.../Documents/connDB.py", line 1, in import mysql.connector ModuleNotFoundError: No module named 'mysql'
(base) lib % which mysql
/usr/local/bin/mysql
(base) lib % which python
/Users/username/anaconda3/bin/python
lib % which python3
/Users/username/anaconda3/bin/python3
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.32 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
So what is stopping Python to be able to connect to my db?
Alright.. I think the issue is either you haven't installed the mysql-connector library or you're not in the correct python environment. Since it most likely be the first case, you have to run the following code in your command line.
Then try running the script.
If it didn't fix your error and you're sure that you installed mysql-connector-python, then you're in the wrong python environment. Since you're using conda first try to view the environment list by running
Then activate the environment by running
Then you're all done. Try running the script again and it should work fine.
P.S : Can anyone explain the reason why I got downvoted?