Django Error loading MySqlDB module - python

I'm new with Django and I follow a tuto. The problem is that the tuto uses Sqlite but I want to use MySql server instead. I changed the parameters following documentation but I have the following error when I try to run the server. I already found some resolve but it didn't work...
For your information, I installed MySql-Python and reinstall Django with PIP. Without any success. I hope you will be able to help me.
Traceback :
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\adescamp>cd C:\Users\adescamp\agregmail
C:\Users\adescamp\agregmail>python manage.py runserver 8000
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 280, in execute
translation.activate('en-us')
File "C:\Python27\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
return _trans.activate(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
_active.value = translation(language)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "C:\Python27\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
app = import_module(appname)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py", line 6, in <module>
from django.contrib.admin.sites import AdminSite, site
File "C:\Python27\lib\site-packages\django\contrib\admin\sites.py", line 4, in <module>
from django.contrib.admin.forms import AdminAuthenticationForm
File "C:\Python27\lib\site-packages\django\contrib\admin\forms.py", line 6, in <module>
from django.contrib.auth.forms import AuthenticationForm
File "C:\Python27\lib\site-packages\django\contrib\auth\forms.py", line 17, in <module>
from django.contrib.auth.models import User
File "C:\Python27\lib\site-packages\django\contrib\auth\models.py", line 48, in <module>
class Permission(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 96, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 264, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Python27\lib\site-packages\django\db\models\options.py", line 124, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 34, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Python27\lib\site-packages\django\db\utils.py", line 198, in __getitem__
backend = load_backend(db['ENGINE'])
File "C:\Python27\lib\site-packages\django\db\utils.py", line 113, in load_backend
return import_module('%s.base' % backend_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\db\backends\mysql\base.py", line 17, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named MySQLdb
Thank you!

I found the solution!
I had to install mysql-python. Easy but: don't do that with PIP because it won't work. You have to install mysql-p

as you are running python on windows. Pip install mysql-python won't work. Try using python-mysql from here http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python

Related

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet launching debug on pycharm

I have a Django (version 1.9) application running with python 2.7.10 and I'm using Virtualenv.
Running the application with ./manage.py runserver I've no error, but when I try to run in debug I get django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Here is the Pycharm debugging configuration:
Any idea why?
Here is the complete stack trace:
/Users/matteobetti/Progetti/Enydros/enysoft/bin/python ./manage.py runserver
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
commands = get_commands()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
result = user_function(*args, **kwds)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I add import django e django.setup before execute_from_command_line(sys.argvs)
and I get this stack trace:
Traceback (most recent call last):
File "/Users/matteobetti/Progetti/Enydros/enysoft/manage.py", line 10, in <module>
django.setup()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/apps.py", line 2, in <module>
from frontend.services.container import app_context
File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/services/container.py", line 1, in <module>
from frontend.services.enysoft_services import RService, FixedSizeDirectoryCache, TubeSectionService, CsvSanifier
File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/services/enysoft_services.py", line 5, in <module>
import rpy2.robjects as ro
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 15, in <module>
import rpy2.rinterface as rinterface
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/rpy2/rinterface/__init__.py", line 16, in <module>
tmp = subprocess.check_output(("R", "RHOME"), universal_newlines=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Another thing to say is that my colleagues with Linux have no problem with the same virtualenv configuration, the only one that has a problem is me, using MacOs.
Try to add you settings file to system PATH. In my projects settings are in the folder /project_name/project_name/settings/development.py (that is slightly different from standard way). And in my case Evironment variables string is
DJANGO_SETTINGS_MODULE=project_name.settings.development;PYTHONUNBUFFERED=1
So change it according to your parameters and then try to run server again. I hope this helps.

How can I install django debug toolbar?

I use ubuntu and I installed the django debug toolbar with pip using sudo pip install django-debug-toolbar. Then I added it to my settings file. Now when I start the django app server I get this error message.
Traceback (most recent call last):
File "./social/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named debug_toolbar
(kthsocial)dac#dac-VPCSA2Z9E:/etc/social/social$ ./social/manage.py runserver
Traceback (most recent call last):
File "./social/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named debug_toolbar
Why doesn't it work?
This is because sudo pip install django-debug-toolbar never installed django-debug-toolbar in your virtualenv. Make sure your virtualenv is activate and use pip install django-debug-toolbar. Don't use sudo
Don't use sudo to install things when you're in a virtualenv.

Django app engine cannot import name old_dev_appserver

I am trying to use django in appengine. I have followed the installation documentation and setup the project. But ./manage.py runserver command is generating error.
Traceback is,
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/salman/projects/appengine/banglapy/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/salman/projects/appengine/banglapy/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/salman/projects/appengine/banglapy/django/core/management/__init__.py", line 263, in fetch_command
app_name = get_commands()[subcommand]
File "/home/salman/projects/appengine/banglapy/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/home/salman/projects/appengine/banglapy/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/salman/projects/appengine/banglapy/django/conf/__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/home/salman/projects/appengine/banglapy/django/conf/__init__.py", line 132, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/salman/projects/appengine/banglapy/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/salman/projects/appengine/banglapy/banglapy/settings.py", line 6, in <module>
from djangoappengine.settings_base import *
File "/home/salman/projects/appengine/banglapy/djangoappengine/settings_base.py", line 8, in <module>
from djangoappengine.utils import on_production_server, have_appserver
File "/home/salman/projects/appengine/banglapy/djangoappengine/utils.py", line 24, in <module>
"Error was: %s" % e)
Exception: Could not get appid. Is your app.yaml file missing? Error was: cannot import name old_dev_appserver
how can I resolve this issue?
Google removed the old dev_appserver from the SDK in version 1.9.17. There is an issue on the djangoappengine project about it as well.
https://github.com/django-nonrel/djangoappengine/issues/95

Error: The 'elasticsearch' backend requires the installation of 'requests'. How do I fix it?

I´m having a issue when I ran "python manage.py rebuild_index" in my app supported by haystack and elasticsearch.
Python 2.7
Django version 1.6.2
Haystack 2.1.0
Elasticsearch 1.0
Please see the error that is appearing:
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 399, in > execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 392, in > execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 242, in >run_from_argv
self.execute(*args, **options.dict)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 15, in handle
call_command('clear_index', **options)
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/haystack/management/commands/clear_index.py", line 48, in handle
backend = connections[backend_name].get_backend()
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 98, in getitem
self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 51, in load_backend
return import_class(full_backend_path)
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 18, in import_class
module_itself = importlib.import_module(module_path)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
import(name)
File "/usr/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 21, in
raise MissingDependency("The 'elasticsearch' backend requires the installation of 'requests'.")
haystack.exceptions.MissingDependency: The 'elasticsearch' backend requires the installation of 'requests'.
I've installed all the packages needed to run those apps however is asking about requests, What is it about?
just do
pip install pyelasticsearch
If you just install requests module through pip this error should go away.

ImportError: No module named modelsinspector

I get the following error when I do syncdb
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 18, in handle_noargs
loaded_models = get_models()
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 167, in get_models
self._populate()
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate
self.load_app(app_name)
File "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app
models = import_module('.models', app_name)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
.
.
.
.
from south.modelsinspector import add_introspection_rules
ImportError: No module named modelsinspector
Why have you installed South 0.5? The current version of South is 0.7.3 - 0.5 is more than two years old and dates from before the reorganisation that added the modelsinspector module. Delete that version and install the latest one.
You are missing module modelsinspector. Install it.

Categories