Miserlou / lambda-packages

Various popular python libraries, pre-compiled to be compatible with AWS Lambda
https://blog.zappa.io
731 stars 163 forks source link

Using mysqldb with lambda and zappa #38

Open stevezau opened 7 years ago

stevezau commented 7 years ago

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?

Miserlou commented 7 years ago

Are you in a venv?

stevezau commented 7 years ago

Yep in a venv on a mac using pycharm.

senseysensor commented 7 years ago

+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.

perwagner commented 7 years ago

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

withalice commented 7 years ago

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

rafaelhenrique commented 7 years ago

Same here.

FlipperPA commented 6 years ago

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.

rafaelhenrique commented 6 years ago

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.

mjscalexander commented 4 years ago

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'