user7257202
user7257202

Reputation:

ModuleNotFoundError: No module named 'MySQLdb' python macOS high sierra

Everytime I execute my python code, it gives me the above ModuleNotFound error when I execute with python3. With python, it gives me an ImportError.

I have updated setuptools using pip install --upgrade setuptools.

I have also tried multiple commands such as: pip install mysqlclient, pip install MySQL-python, pip install pymysql.

I have tried these commands with pip3 as well (Not sure if it makes a difference).

Everytime I try these commands, it gives me the following error:

Complete output from command python setup.py egg_info:
    /bin/sh: mysql_config: command not found
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient/setup.py", line 16, in <module>
        metadata, options = get_config()
      File "/private/var/folders/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient/setup_posix.py", line 51, in get_config
        libs = mysql_config("libs")
      File "/private/var/folders/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient/setup_posix.py", line 29, in mysql_config
        raise EnvironmentError("%s not found" % (_mysql_config_path,))
    OSError: mysql_config not found

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/0y/xsr1t8rs36l0vlq3_f2q42g40000gn/T/pip-install-soxlcjei/mysqlclient

How do I fix this? I am using a macOS High Sierra. I have gone through solutions for similar problems on ubuntu/debian systems and have to tried to apply it here. None of that works on a mac. Also, i already have mysql installed and it works perfectly. It is constantly running on my system.

Upvotes: 3

Views: 3431

Answers (1)

Lee
Lee

Reputation: 11

you should download a tar named as Mysql-python-1.2.4b4.tar.gz, and unzip it, cd to the dir and update the file site.cfg: # mysql_config = /usr/local/mysql/bin/mysql_config to mysql_config = /usr/local/mysql/bin/mysql_config and then python setup.py install, after you installed the mysql-python,then you can not get the error.

Upvotes: 1

Related Questions