To give a bit of context, I'm working in internship on the upgrade of a Django app from 1.4.22 to 1.11 and python 2 to 3.
The project wasn't well factored, and when I tried to refactor it, I got a strange stack :
Traceback (most recent call last):
File "/home/antonin/Developpement/Projet/djangoproject2/djangoproject/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
django.setup()
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/antonin/Developpement/Projet/djangoproject2/djangoproject/instance/models.py", line 54, in <module>
YEARS += [(str(yr), _(u"n+%(year)d") % {'year': yr}) for yr in range(1, 20)]
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/functional.py", line 179, in __mod__
return six.text_type(self) % rhs
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/functional.py", line 144, in __text_cast
return func(*self.__args, **self.__kw)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 83, in ugettext
return _trans.ugettext(message)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 325, in ugettext
return do_translate(message, 'ugettext')
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 306, in do_translate
_default = translation(settings.LANGUAGE_CODE)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 209, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 195, in _fetch
res = _merge(apppath)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in _merge
t = _translation(path)
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _translation
t = gettext_module.translation('django', path, [loc], DjangoTranslation)
File "/usr/lib64/python2.7/gettext.py", line 554, in translation
t = _translations.setdefault(key, class_(fp))
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 107, in __init__
gettext_module.GNUTranslations.__init__(self, *args, **kw)
File "/usr/lib64/python2.7/gettext.py", line 255, in __init__
self._parse(fp)
File "/usr/lib64/python2.7/gettext.py", line 348, in _parse
magic = unpack('<I', buf[:4])[0]
struct.error: unpack requires a string argument of length 4
When I tried to debug, with step by step mode, I saw that the issue is at the line
File "/home/antonin/Developpement/Projet/djangoproject2/venv/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 107, in __init__
gettext_module.GNUTranslations.__init__(self, *args, **kw)
where fp.read() receive a u'path/to/file.po' (path which is correct) and return a empty buffer. But I don't see any reasons why this appens.
Edit : thanks, håken, it was Indeed the .mo files that were corrupted. Problem solved.
I'm not quite sure what is going wrong here, I have added all the apps in settings.py file, successfully ran the migrations with manage.py etc. but i keep getting this error.
I'm running this in PyCharm 2017.2.2 and I don't see any errors in my scripts either. All the required packages seems to be installed.
Below is the stack trace :
__import__(module)
from models import Token, Narrative
self = load(from_parent)
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
File "C:\Python27\lib\pickle.py", line 1384, in load
__import__(module)
return Unpickler(file).load()
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
from models import Token, Narrative
class Narrative(models.Model):
File "C:\Python27\lib\pickle.py", line 864, in load
return Unpickler(file).load()
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
File "C:\Python27\lib\pickle.py", line 864, in load
from models import Token, Narrative
dispatch[key](self)
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
class Narrative(models.Model):
app_config = apps.get_containing_app_config(module)
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1096, in load_global
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
File "C:\Python27\lib\pickle.py", line 1096, in load_global
klass = self.find_class(module, name)
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
class Narrative(models.Model):
self.check_apps_ready()
klass = self.find_class(module, name)
File "C:\Python27\lib\pickle.py", line 1130, in find_class
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
File "C:\Python27\lib\pickle.py", line 1130, in find_class
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
app_config = apps.get_containing_app_config(module)
__import__(module)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
raise AppRegistryNotReady("Apps aren't loaded yet.")
__import__(module)
app_config = apps.get_containing_app_config(module)
django.core.exceptions File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
self.check_apps_ready()
from models import Token, Narrative
. File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
AppRegistryNotReadyfrom models import Token, Narrative
self.check_apps_ready()
: File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
class Narrative(models.Model):
A django.core.exceptions File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
pps aren't loaded yet.class Narrative(models.Model):
raise AppRegistryNotReady("Apps aren't loaded yet.")
.
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
django.core.exceptionsAppRegistryNotReadyapp_config = apps.get_containing_app_config(module)
.: File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
app_config = apps.get_containing_app_config(module)
AppRegistryNotReadyA File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
: pps aren't loaded yet. self.check_apps_ready()
A
self.check_apps_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
pps aren't loaded yet. File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
Traceback (most recent call last):
raise AppRegistryNotReady("Apps aren't loaded yet.")
Traceback (most recent call last):
File "<string>", line 1, in <module>
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
django.core.exceptions. File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
.AppRegistryNotReadyAppRegistryNotReadyself = load(from_parent)
: : File "C:\Python27\lib\pickle.py", line 1384, in load
self = load(from_parent)
AA File "C:\Python27\lib\pickle.py", line 1384, in load
Traceback (most recent call last):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
pps aren't loaded yet. pps aren't loaded yet.return Unpickler(file).load()
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
[26/Aug/2017 13:02:01] "GET /getStatus HTTP/1.1" 200 3
File "C:\Python27\lib\pickle.py", line 864, in load
return Unpickler(file).load()
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 864, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1384, in load
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1096, in load_global
File "C:\Python27\lib\pickle.py", line 1384, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1096, in load_global
return Unpickler(file).load()
klass = self.find_class(module, name)
File "C:\Python27\lib\pickle.py", line 864, in load
File "C:\Python27\lib\pickle.py", line 1130, in find_class
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 864, in load
klass = self.find_class(module, name)
dispatch[key](self)
__import__(module)
File "C:\Python27\lib\pickle.py", line 1130, in find_class
File "C:\Python27\lib\pickle.py", line 1096, in load_global
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1096, in load_global
__import__(module)
klass = self.find_class(module, name)
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
from models import Token, Narrative
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
Traceback (most recent call last):
klass = self.find_class(module, name)
File "C:\Python27\lib\pickle.py", line 1130, in find_class
File "<string>", line 1, in <module>
from models import Token, Narrative
File "C:\Python27\lib\pickle.py", line 1130, in find_class
class Narrative(models.Model):
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
__import__(module)
class Narrative(models.Model):
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
__import__(module)
self = load(from_parent)
app_config = apps.get_containing_app_config(module)
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
File "C:\Python27\lib\pickle.py", line 1384, in load
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
from models import Token, Narrative
app_config = apps.get_containing_app_config(module)
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
from models import Token, Narrative
self.check_apps_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
class Narrative(models.Model):
self.check_apps_ready()
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
class Narrative(models.Model):
raise AppRegistryNotReady("Apps aren't loaded yet.")
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
django.core.exceptions app_config = apps.get_containing_app_config(module)
.return Unpickler(file).load()
raise AppRegistryNotReady("Apps aren't loaded yet.")
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
AppRegistryNotReadyapp_config = apps.get_containing_app_config(module)
File "C:\Python27\lib\pickle.py", line 864, in load
django.core.exceptions: File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
.A self.check_apps_ready()
AppRegistryNotReadypps aren't loaded yet.self.check_apps_ready()
: File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
A pps aren't loaded yet.dispatch[key](self)
raise AppRegistryNotReady("Apps aren't loaded yet.")
File "C:\Python27\lib\pickle.py", line 1096, in load_global
django.core.exceptions .raise AppRegistryNotReady("Apps aren't loaded yet.")
klass = self.find_class(module, name)
AppRegistryNotReadydjango.core.exceptions File "C:\Python27\lib\pickle.py", line 1130, in find_class
: . AAppRegistryNotReady__import__(module)
pps aren't loaded yet.: File "C:\Users\moham\Downloads\GQP Project\final\app1\tokenization.py", line 34, in <module>
A pps aren't loaded yet.from models import Token, Narrative
File "C:\Users\moham\Downloads\GQP Project\final\app1\models.py", line 27, in <module>
class Narrative(models.Model):
File "C:\Python27\lib\site-packages\django\db\models\base.py", line 110, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 247, in get_containing_app_config
self.check_apps_ready()
File "C:\Python27\lib\site-packages\django\apps\registry.py", line 125, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
Traceback (most recent call last):
Traceback (most recent call last):
self = load(from_parent)
File "<string>", line 1, in <module>
Traceback (most recent call last):
File "<string>", line 1, in <module>
Traceback (most recent call last):
File "C:\Python27\lib\pickle.py", line 1384, in load
Traceback (most recent call last):
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
File "<string>", line 1, in <module>
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
I am trying install django-cms. But I got following error
Traceback (most recent call last):
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run
autoreload.raise_last_exception()
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 252, in raise_last_exception
six.reraise(*_exception)
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/savad/virtuals/kw/local/lib/python2.7/site-packages/django/apps/config.py", line 119, in create
import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named sitescms
I used django-cms==3.4.2 and django==1.8.17.
To me it looks like you're missing a comma in the list of your INSTALLED_APPS in settings.py.
Could it be that it says
...,
'sites'
'cms',
...
instead of
...,
'sites',
'cms',
....
The missing comma results in sitescms.
I am new to django.
I get this error when I update settings.py with database and run
$python2.7 manage.py migrate
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
module: libperconaserverclient.so.18: cannot open shared object file:
No such file or directory
Is it because of version of mysql ? if so which version should I use ?
$ python2.7 manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/sachints/project/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 327, in execute
django.setup()
File "/home/sachints/project/env/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/contrib/auth/models.py", line 4, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/home/sachints/project/env/lib/python2.7/site-packages/django/contrib/auth/base_user.py", line 49, in <module>
class AbstractBaseUser(models.Model):
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/base.py", line 108, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/base.py", line 299, in add_to_class
value.contribute_to_class(cls, name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/models/options.py", line 263, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/__init__.py", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/utils.py", line 212, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/utils.py", line 116, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/sachints/project/env/lib/python2.7/site-packages/django/db/backends/mysql/base.py", line 28, in <module>
raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: libperconaserverclient.so.18: cannot open shared object file: No such file or directory
I am using RHEL 6.7, MySql Server version: 5.1.73 and Python 2.7.11
yum -y install mysql-devel
ln -s /usr/local/mysql/lib/libperconaserverclient_r.so.18 /usr/lib
ln -s /usr/local/mysql/lib/libperconaserverclient_r.so /usr/lib
Idconifg
done!
unable to start C:\Python27\mysastha>python manage.py runserver
c:\python27\lib\site-packages\djangotoolbox-1.6.2-py2.7.egg\djangotoolbox\db\uti
ls.py:5: RemovedInDjango19Warning: django.utils.unittest will be removed in Djan
go 1.9.
from django.utils.unittest import skip
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\core\managemen
t\__init__.py", line 330, in execute_from_command_line
utility.execute()
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\core\managemen
t\__init__.py", line 304, in execute
django.setup()
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\__init__.py",
line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\apps\registry.
py", line 108, in populate
app_config.import_models(all_models)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\apps\config.py
", line 197, in import_models
self.models_module = import_module(models_module_name)
File "c:\python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\contrib\auth\m
odels.py", line 40, in <module>
class Permission(models.Model):
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\base
.py", line 127, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\base
.py", line 303, in add_to_class
value.contribute_to_class(cls, name)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\models\opti
ons.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\__init__.py
", line 36, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\utils.py",
line 238, in __getitem__
backend = load_backend(db['ENGINE'])
File "c:\python27\lib\site-packages\django-1.8-py2.7.egg\django\db\utils.py",
line 127, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an av
ailable database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
u'django_mongodb_engine', u'mysql', u'oracle', u'postgresql_psycopg2', u'sql
ite3'
Error was: cannot import name decimal_to_string
Just follow the instructions in the trace back. you need django.db.backends.django_mongodb_engine as the engine. Not just django_mongodb_engine.
If you havent already you will probably need a couple dependencies for the engine to work. im on mobile and dont know what they are called at the moment for mongodb