import mysql.connector gives error

123 views
Skip to first unread message

abir apskol

unread,
Apr 1, 2020, 11:29:57 AM4/1/20
to spyder
import mysql.connector

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

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE mydatabase")

this is the prog i want to run

 runfile('C:/Users/ABIR/AppData/Local/Programs/Python/Python37/untitled0.py', wdir='C:/Users/ABIR/AppData/Local/Programs/Python/Python37')
Traceback (most recent call last):

  File "C:\Users\ABIR\AppData\Local\Programs\Python\Python37\untitled0.py", line 8, in <module>
    import mysql.connector

  File "C:\Users\ABIR\mysql.py", line 1, in <module>
    import mysql.connector

ModuleNotFoundError: No module named 'mysql.connector'; 'mysql' is not a package

this error msg I am getting.
I have successfully installed the mysql package
please help

Jim Lareau

unread,
Apr 1, 2020, 10:42:37 PM4/1/20
to spyder
Have you installed the mysql-connector-python package? See:

https://enterprise-docs.anaconda.com/en/latest/data-science-workflows/data/mysql.html

Naidu

unread,
May 9, 2022, 11:14:50 AM5/9/22
to spyder
Guys, can anyone help me. to solve this....
conda install -c anaconda mysql-connector-python
i was try this code several times i cannot understand the errror.

Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: \
Found conflicts! Looking for incompatible packages.
This can take several minutes.  Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

  - mysql-connector-python -> python[version='>=3.5,<3.6.0a0|>=3.6,<3.7.0a0|>=3.7,<3.8.0a0']

Your python: python=3.9

If python is on the left-most side of the chain, that's the version you've asked for.
When python appears to the right, that indicates that the thing on the left is somehow
not available for the python version you are constrained to. Note that conda will not
change your python version to a different minor version unless you explicitly specify
that.
Reply all
Reply to author
Forward
0 new messages