lambda-packages icon indicating copy to clipboard operation
lambda-packages copied to clipboard

Using mysqldb with lambda and zappa

Open stevezau opened this issue 8 years ago • 9 comments

Hi,

Following to instructions, simple installing this package, or letting zappa install it does not seem to give me mysqldb within my lambda function. I get

[1489527885652] ImportError: No module named MySQLdb

Am i missing something here? I also checked the package zip and it's not in there either. I am running mac though, do i need to run package on an aws machine?

stevezau avatar Mar 14 '17 22:03 stevezau

Are you in a venv?

Miserlou avatar Mar 14 '17 22:03 Miserlou

Yep in a venv on a mac using pycharm.

stevezau avatar Mar 14 '17 22:03 stevezau

+1. After deploying with zappa import MySQLdb results in ImportError No module named MySQLdb

Only lambda-packages module is installed, standard MySQLdb module is not.

senseysensor avatar Apr 20 '17 10:04 senseysensor

I'm using Python 3.6 and have the same problem.

perwagner avatar Jun 23 '17 01:06 perwagner

I'm also using Python 3.6 and have the same problem !!

withalice avatar Jul 05 '17 03:07 withalice

Same here.

rafaelhenrique avatar Aug 09 '17 21:08 rafaelhenrique

Silly question, but are you using MySQLdb or mysqlclient? If you're using a venv against the system Python on a Mac, you're using Python 2, instead of Python 3.6. mysqlclient is supposed to be a "drop-in" replacement for MySQLdb, but with Python 3 compatibility:

https://docs.djangoproject.com/en/1.11/ref/databases/#mysql-db-api-drivers

MySQLdb only supports Python 2, and support for it is being dropped in Django 2.0.

FlipperPA avatar Oct 25 '17 20:10 FlipperPA

Hi @FlipperPA !

I tried to use mysqlclient (with Python3), but many incompatibilities happen, the instance "image" provisioned in lambda does not have libmariaXXX.so (Maria DB / MysqlDB libraries).

But MySQLdb with Python 2 works fine.

rafaelhenrique avatar Oct 25 '17 22:10 rafaelhenrique

I am having this same error. Error loading MySQLdb module: No module named 'MySQLdb': ImproperlyConfigured Traceback (most recent call last): File "/var/task/process.py", line 169, in main process(record, context) File "/var/task/process.py", line 133, in process django.setup() File "/var/task/django/init.py", line 27, in setup apps.populate(settings.INSTALLED_APPS) File "/var/task/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/var/task/django/apps/config.py", line 199, in import_models self.models_module = import_module(models_module_name) File "/var/lang/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 994, in _gcd_import File "", line 971, in _find_and_load File "", line 955, in _find_and_load_unlocked File "", line 665, in _load_unlocked File "", line 678, in exec_module File "", line 219, in _call_with_frames_removed File "/var/task/django/contrib/auth/models.py", line 4, in from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "/var/task/django/contrib/auth/base_user.py", line 52, in class AbstractBaseUser(models.Model): File "/var/task/django/db/models/base.py", line 119, in new new_class.add_to_class('_meta', Options(meta, app_label)) File "/var/task/django/db/models/base.py", line 316, in add_to_class value.contribute_to_class(cls, name) File "/var/task/django/db/models/options.py", line 214, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "/var/task/django/db/init.py", line 33, in getattr return getattr(connections[DEFAULT_DB_ALIAS], item) File "/var/task/django/db/utils.py", line 211, in getitem backend = load_backend(db['ENGINE']) File "/var/task/django/db/utils.py", line 115, in load_backend return import_module('%s.base' % backend_name) File "/var/lang/lib/python3.6/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "/var/task/django/db/backends/mysql/base.py", line 28, in raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'

mjscalexander avatar Mar 02 '20 22:03 mjscalexander