Error loading Mysqldb module in Python Django - python

I am currently working on Ubuntu 14.10/Python/Django/MySQL and encountering the following error when I try to run:
$python manage.py makemigrations polls
or
$python manage.py migrate polls
I have also tried syncdb
The error is:
(Aaronpythonenv)aaron#aaron-N550JK:~/mysite$ python manage.py makemigrations polls
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 338, in execute_from_command_line
utility.execute()
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/init.py", line 312, in execute
django.setup()
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/init.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/contrib/auth/models.py", line 41, in
class Permission(models.Model):
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 139, in new
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/base.py", line 324, in add_to_class
value.contribute_to_class(cls, name)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/models/options.py", line 250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/init.py", line 36, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 240, in getitem
backend = load_backend(db['ENGINE'])
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
File "/home/aaron/Aaronpythonenv/local/lib/python2.7/site-packages/Django-1.8-py2.7.egg/django/db/backends/mysql/base.py", line 27, in
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
I have used PIP to install mysql-python to my environment which I recieved another error. I then used sudo apt-get command to install correct the error PIP brought up.
massive thank you in advance please let me know if I need to add anything else.

I faced somewhat similar problem. Try these steps:
1). Upgrade pip to the latest version.
sudo pip install pip --upgrade
2). Build the dependencies for python-mysqldb libraries:
sudo apt-get build-dep python-mysqldb
3). Install the Python MySQL libraries:
sudo pip install MySQL-python

I think it means there is no module named mysqldb.
You just need to setup the mysqldb module.
For example if you use the ubuntu, you just need to run this command:
sudo apt-get install python-mysqldb
and then you problem will be fixed!

Related

import sqlparse ModuleNotFoundError: No module named 'sqlparse'

I have installed
pip install sqlparse
pip3 install sqlparse
conda install sqlparse
But still getting sqlparse module error
Why is that?
(New4) C:\Users\zesha\Documents\GitHub\django-blog>python manage.py makemigrations
Traceback (most recent call last):
File "C:\Users\zesha\Documents\GitHub\django-blog\manage.py", line 21, in <module>
main()
File "C:\Users\zesha\Documents\GitHub\django-blog\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\ProgramData\Miniconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\utils.py", line 214, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "C:\ProgramData\Miniconda3\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\base.py", line 32, in <module>
from .introspection import DatabaseIntrospection # isort:skip
File "C:\Users\zesha\AppData\Roaming\Python\Python39\site-packages\django\db\backends\sqlite3\introspection.py", line 4, in <module>
import sqlparse
ModuleNotFoundError: No module named 'sqlparse'
I am getting the following error.
I am not sure where should I install sqlparse
Since you also tried conda install, I am supsecting that you have anaconda or miniconda installed. pip and pip3 probably point to the python version managed by conda. However, your error message suggests that your script is being executed with a python version that is located at
C:\Users\zesha\AppData\Roaming\Python\Python39\
To install for that version of python specifically, you could try something like (might need to check that that is actual path to python.exe in that folder):
C:\Users\zesha\AppData\Roaming\Python\Python39\python.exe -m pip install sqlparse
Alternatively, run your script with the python that is managed by conda

Error loading psycopg2 module: dlopen with virtualenv django python 2.7

Guys I stuck this problem for couple weeks already. I have tried almost every answer I could find in stack overflow.
The error is below:
(venv1) Caimings-MacBook-Pro:yang NLStom$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/apps/config.py", line 199, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
class AbstractBaseUser(models.Model):
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/models/base.py", line 119, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/models/base.py", line 316, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/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 "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/__init__.py", line 33, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/utils.py", line 211, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/utils.py", line 115, in load_backend
return import_module('%s.base' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/psycopg2/_psycopg.so, 2): Symbol not found: _PQbackendPID
Referenced from: /Users/NLStom/Desktop/hey/yang/venv1/lib/python2.7/site-packages/psycopg2/_psycopg.so
Expected in: dynamic lookup
I tried to using PostgreSql for my database in Django.
Below is code in my setting
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'play',
'USER': 'uaa',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '',
}
}
What have I did in PostgreSql.
psql (9.5.4)
Type "help" for help.
NLStom=# CREATE uaa;
ERROR: syntax error at or near "uaa"
LINE 1: CREATE uaa;
^
NLStom=# CREATE USER uaa;
CREATE ROLE
NLStom=# CREATE DATABASE play OWNER uaa;
CREATE DATABASE
NLStom=# \q
I used pip brew to install PostgreSql and used pip to install psycopg2.
I have done all of these above in virtualenv.
Also wanna mention that I install Postgres.app in my mac.
I got a similar error, but once I verified that psql was in my PATH and the postgres server was running in the background, I reinstalled psycopg2 with conda install psycopg2, and my django postgres app worked fine.
Got similar issue on macOS 11.01, M1 Chip.
Solved it by deleting the venv created by pycharm and recreating it manually with python3 -m venv /path/to/venv and then pip3 install -r requirements.txt.
Following github issue could be helpful.

"No module name mysqldb" error in django [duplicate]

This question already has answers here:
pip install mysql-python fails with EnvironmentError: mysql_config not found
(24 answers)
Closed 7 years ago.
i have install django 1.7(python 2.7.6) on ubantu 14.04 with mysql database engine but on running command-
python manage.py migrate
i am getting below error
(env1)shiv#shiv-Calpella:~/Project/Poll_app/mysite$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
class Permission(models.Model):
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/models/base.py", line 297, in add_to_class
value.contribute_to_class(cls, name)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/shiv/Envs/env1/local/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 18, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
i have tried installing mysqldb by commands
pip install MySQL-python
then i am getting below error
(env1)shiv#shiv-Calpella:~/Project/Poll_app/mysite$ pip install MySQL-pythonCollecting MySQL-python
Using cached MySQL-python-1.2.5.zip
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-3FRYWs/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
Complete output from command python setup.py egg_info:
sh: 1: mysql_config: not found
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/tmp/pip-build-3FRYWs/MySQL-python/setup.py", line 17, in <module>
metadata, options = get_config()
File "setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "setup_posix.py", line 25, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-3FRYWs/MySQL-python
my setting.py file is
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'poll_db',
'USER': 'root',
'PASSWORD': 'root',
}
}
In the above example, the answer might be in the proper log file pip.log or somewhere in /tmp/pip-build-rHe_Sb/MySQL-python.
1) When installing MySQL module with PIP, please make sure you have installed for instance the mysql-devel (yum) or libmysqlclient-dev (apt-get) package in your system.
2) BTW, I would recommend mysqlclient ($ pip install mysqlclient) instead of MySQL-python, as it supports both Python 2 and 3.x.
You have 2 options, as described bellow:
Distribution package are-:
sudo apt-get install python-mysqldb
In this case you can't use virtualenv no-site-packages (default option) but must use:
virtualenv --system-site-packages myenv
Use clean virtualenv and build your own python-mysql package.
First create virtualenv:
virtualenv myvirtualenv
source myvirtualenv/bin/activate
Then install build dependencies:
sudo apt-get build-dep python-mysqldb
Now you can install python-mysql
pip install mysql-python
NOTE Ubuntu package is python-mysqldb , python pypi package is python-mysql (without db)

Installing psycopg2 in a virtualenv in ubuntu os

I using a virtualenv and I am trying to set up postgresql. I have psycopg2 installed on my system, but it appears that my virtual env does not recognize psycopg2. Is it possible to just copy the system wide psycopg2 files into my django project directory or is this a bad approach to take?
This is the relevant part of my settings.py file in my django project.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'django_db' ,
'USER': 'myusername' ,
'PASSWORD': 'mypassword' ,
'HOST': 'localhost' ,
'PORT': '' ,
}
}
When I run python manage.py migrate I get this error:
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
class Permission(models.Model):
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/models/base.py", line 125, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/models/base.py", line 300, in add_to_class
value.contribute_to_class(cls, name)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2
When I do pip install psycopg2 in my virtual env, I get the following error:
Exception:
Traceback (most recent call last):
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/basecommand.py", line 122, in main
status = self.run(options, args)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/commands/install.py", line 278, in run
requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/req.py", line 1153, in prepare_files
location = req_to_install.build_location(self.build_dir, not self.is_download)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/req.py", line 218, in build_location
_make_build_dir(build_dir)
File "/uwsgi-tutorial/local/lib/python2.7/site-packages/pip/req.py", line 1527, in _make_build_dir
os.makedirs(build_dir)
File "/uwsgi-tutorial/lib/python2.7/os.py", line 157, in makedirs
mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/uwsgi-tutorial/build'
Storing debug log for failure in /home/user/.pip/pip.log
This is an old thread but some people might experience Python.h not found type of error while pip-installing psycopg2 to virtualenv on Ubuntu based systems.
Check your virtualenv python version by running python -V inside virtualenv.
Assuming it is Python 3.8.0, try installing libpython3.8-dev to your system (not virtualenv) by:
sudo apt-get install libpython3.8-dev
Probably similar approach with other versions.
That solved it for me.
Based on the combination of your question and one of your comments, it appears that when you ran sudo pip install psycopg2, it was using the system install, as it referred to psycopg2 in /usr/lib/python2.7/dist-packages which is different from the environment from which you're trying to run Django.
Your permissions error, which is from the Django environment, seems likely to be due to not using sudo (among other things, some C compilation needs to take place, during the psycopg2 install, and so sudo is often required whereas it isn't with many other packages).
I would recommend you refer to the virtualenv install's pip binary explicitly when running the sudo command.
i.e.: sudo <virtualenv_root>/bin/pip install psycopg2
Something that worked for me (python 3.8 in virtualenv):
Inside the virtual environment type:
pip install psycopg2-binary
Best.

Django 1.4.1 error loading MySQLdb module when attempting 'python manage.py shell'

I am trying to set up MySQL, and can't seem to be able to enter the Django manage.py shell interpreter. I did install MySQL-python but that did not solve the issue.
Getting the output below:
rrdhcp-10-32-44-126:django pavelfage$ python manage.py shell
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 45, in handle_noargs
from django.db.models.loading import get_models
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 40, in <module>
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 92, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/utils.py", line 24, in load_backend
return import_module('.base', backend_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 16, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named _mysql
Any suggestions really appreciated.
You are probably missing the MySQLdb module. You basically just have to install it.
By the looks of it, you are using a Mac, so you might want to check out this answer for detailed installation instructions: How to install MySQLdb (Python data access library to MySQL) on Mac OS X?
On a totally alternate solution, as you mentionned Django development you might want to use sqlite3 instead of MySQL, which could be simpler to install.
You should be able to import MySQLdb from python shell.
Try importing MySQLdb from python shell not django
If you can not import MySQLdb from python shell;
It may caused because of 32-64 bit mismatch,
Try this link

Categories

Resources