0

I am on MacOS 11.6 and having trouble installing the mysql package for python3. Other python packages are working fine.

which python3 returns /Library/Frameworks/Python.framework/Versions/3.10/bin/python3 and python3 --version returns Python 3.10.5.

I run the command python3 -m pip install mysql.

Running python3 -m pip list verifies the following packages are installed:

mysql              0.0.3
mysqlclient        2.1.1

Next I run python3 and execute at the prompt:

>>> import mysql

and get the error ModuleNotFoundError: No module named 'mysql'

When I change to directory /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages and do an ls I see:

mysql-0.0.3.dist-info/
mysqlclient-2.1.1-py3.10.egg-info/

but there is no mysql-0.0.3 directory. Only the dist-info and egg-info directories are there.

Why isn't the package installing correctly? I've scoured all of the related posts but nothing I've found has solved my particular problem. Thank you for your help!

2 Answers 2

1
+50

Install official mysql connector package.

$ pip install mysql-connector-python

For details:

MySQL Connector/Python Developer Guide

Manual download and install from archives, select your OS while downloading.

Manual download and install, latest version

After installation:

from mysql import connector
connect = connector.connect(host='localhost', user='DB_USER', password='DB_PASSWORD', database='DB_NAME')
cursor = connect.cursor(buffered=True)
cursor.execute('SHOW TABLES')
result = cursor.fetchall()
0

mysql is a ghost package.

My sql on pypi’s only purpose is to install other packages in it’s requirements that is why it is a ghost package. So you’ll have to find the actual package you want to use that was installed via pip install mysql

2
  • Where would the actual package be, if not in site-packages?
    – skrilmps
    Commented Jun 27, 2022 at 19:30
  • It would be there just not called mysql @skrilmps Commented Jun 27, 2022 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.