users@glassfish.java.net

Django-Jython-Glassfish-MySQL

From: Keenan, Bill <Bill_Keenan_at_intuit.com>
Date: Thu, 5 Aug 2010 11:17:52 -0700

The error, when running 'jython manage.py syncdb' on a new project, is:
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb

I am following http://weblogs.java.net/blog/vivekp/archive/2009/06/run_django_appl_1.html

Versions:
Django - 1.2.1
Jython - 2.5.1-1.0
Jython Container - 0.5.6-1.1
Django-Jython - 1.1.1
Glassfish - 3.0.1
MySQL - 5.1.47 MySQL Community Server
mysql-connector-java - 5.1.13
MacOS X - 10.6.4

mysql-connector-java is installed in /Applications/NetBeans/sges-v3/glassfish/lib

http://localhost:8080/mysite displays as show in Vivek's blog.

I created in MySQL a user account for mysite.

From .../mysite/settings.py:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'mysite', # Or path to database file if using sqlite3.
        'USER': 'mysite', # Not used with sqlite3.
        'PASSWORD': 'mysite', # Not used with sqlite3.
        'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
        'PORT': '', # Set to empty string for default. Not used with sqlite3.
    }
}


I can connect to the database with admin tools and a local copy of wordpress.

I did not set/adjust CLASSPATH, as the MySQL connector is in glassfish/lib.

Since I get the following traceback, I clearly do not have something configured correctly. I should appreciate your help...

BillK

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/__init__.py", line 257, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/commands/syncdb.py", line 7, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/core/management/sql.py", line 5, in <module>
    from django.contrib.contenttypes import generic
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/contrib/contenttypes/generic.py", line 6, in <module>
    from django.db import connection
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/db/__init__.py", line 75, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/db/utils.py", line 91, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/db/utils.py", line 32, in load_backend
    return import_module('.base', backend_name)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/db/utils.py", line 32, in load_backend
    return import_module('.base', backend_name)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/Applications/NetBeans/sges-v3/glassfish/jython/Lib/site-packages/django/db/backends/mysql/base.py", line 14, in <module>
    raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb