Cara Mengatasi “ImportError: No module named MySQLdb” di Python
Pesan error ImportError: No module named MySQLdb pada aplikasi berbasis framework Python seperti Flask atau Django karena library mysqlclient belum terinstall di sistem operasi dan library MySQL untuk Python belum terinstall.
1 2 3 4 5 6 7 8 9 10 | return connector.get_engine() File "/home/musa/ems/env/local/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py", line 559, in get_engine self._engine = rv = sqlalchemy.create_engine(info, **options) File "/home/musa/ems/env/local/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 391, in create_engine return strategy.create(*args, **kwargs) File "/home/musa/ems/env/local/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 80, in create dbapi = dialect_cls.dbapi(**dbapi_args) File "/home/musa/ems/env/local/lib/python2.7/site-packages/sqlalchemy/dialects/mysql/mysqldb.py", line 110, in dbapi return __import__('MySQLdb') ImportError: No module named MySQLdb |
Install paket libmysqlclient-dev, python-dev
1 | apt-get install libmysqlclient-dev python-dev |
Install MySQL-python via pip
1 | pip install MySQL-python |
selamat mencoba 🙂