How do I install MySQLdb on my MacBook or is there a way I can skip install and use sqlalchemy without it? I have macOS Sierra and XAMPP installed (with mariadb as database).

However, on my local MacBook I am running this Python code to create table:

from sqlalchemy import create_engine

def create_db():
    from sqlalchemy.orm import sessionmaker
    engine = create_engine("mysql://username:password@localhost/exchange_rate", echo = True)
    # Session = sessionmaker(bind = engine)
    # session = Session()
    # import pdb
    # pdb.set_trace()
    meta = MetaData()
    exchange_rate = Table(
        'inr_exchange_rate', meta, 
        Column('id', Integer, primary_key = True), 
        Column('as_of', Date), 
        Column('rate_per_usd', Float), 
        Column('last_modified', DateTime),
        )
    meta.create_all(engine)
    return True


if __name__ == '__main__':
    parser = get_parser()
    args = parser.parse_args()
    print(args)
    if args.create_db:
        print("Create db called;")
        create_db()
        exit(0)


but I get this error

Traceback (most recent call last):
  File "exchange_rate.py", line 73, in &lt;module&gt;
    create_db()
  File "exchange_rate.py", line 50, in create_db
    engine = create_engine("mysql://username:password@localhost/exchange_rate", echo = True)
  File "/Library/Python/2.7/site-packages/sqlalchemy/engine/__init__.py", line 386, in create_engine
    return strategy.create(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/sqlalchemy/engine/strategies.py", line 75, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/Library/Python/2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 92, in dbapi
    return __import__('MySQLdb')
ImportError: No module named MySQLdb


then I tried to follow instruction on the link given by @bmike: 

$ sudo pip3 install MySQL-python
Collecting MySQL-python
  Downloading https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip (108kB)
     |████████████████████████████████| 112kB 490kB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/local/opt/python/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/tmp/pip-install-oxqg62fi/MySQL-python/setup.py'"'"'; __file__='"'"'/private/tmp/pip-install-oxqg62fi/MySQL-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: /private/tmp/pip-install-oxqg62fi/MySQL-python/
    Complete output (7 lines):
    Traceback (most recent call last):
      File "&lt;string&gt;", line 1, in &lt;module&gt;
      File "/private/tmp/pip-install-oxqg62fi/MySQL-python/setup.py", line 13, in &lt;module&gt;
        from setup_posix import get_config
      File "/private/tmp/pip-install-oxqg62fi/MySQL-python/setup_posix.py", line 2, in &lt;module&gt;
        from ConfigParser import SafeConfigParser
    ModuleNotFoundError: No module named 'ConfigParser'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.


but If I try to install config parser, I get its already installed message.

$ pip3 install ConfigParser
Requirement already satisfied: ConfigParser in /usr/local/lib/python3.7/site-packages (4.0.2)
To address the MySQLdb error - try reinstalling the package and then test just that.

sudo easy_install pip 
pip install MySQL-python
python -c "import MySQLdb"


https://stackoverflow.com/a/22513919/475228

The above link would be if you can’t get this going - using homebrew to install MySQL helps with path and getting you set up with the proper environment / diagnostics and easy updating as the software gets patched over time. But, you don’t need that to reinstall the package that threw the error.

Also - be sure you choose python3 or python2 - it’s a bit of a hassle to mix them if you can even get that to work. If you are going to have both I’ll double down on using homebrew to manage things instead of using XAMPP.