Django Project not running - python

I have a simple django project. Installed python,django and mysql database in my ubuntu to run this project. In order to run my project I am trying to sync database first. But when I am trying command "python manage.py syndb" I am getting following errors:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 252, in fetch_command
app_name = get_commands()[subcommand]
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 101, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/lib/python2.7/dist-packages/django/utils/functional.py", line 276, in __getattr__
self._setup()
File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.7/dist-packages/django/conf/__init__.py", line 139, in __init__
logging_config_func(self.LOGGING)
File "/usr/lib/python2.7/logging/config.py", line 777, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python2.7/logging/config.py", line 562, in configure
'filter %r: %s' % (name, e))
ValueError: Unable to configure filter 'require_debug_false': Cannot resolve 'django.utils.log.RequireDebugFalse': No module named RequireDebugFalse
I am very new to python and django. doing it first time..

django.utils.log.RequireDebugFalse appeared in Django 1.4.0. Could it be you have an older Django version installed ?

As you stated in the comment, you installed Django from your distro's repository. Those versions are often old, and indeed it looks like you have installed version 1.3, which is now three versions out of date.
You should remove that version (with apt-get remove) and install the current version from the Python package index, via pip install django. You will probably need to install pip first, which you can do with apt-get.

Related

Django Mezzanine ImportError: No module named apps

I had a working mezzanine project configured with apache and mod_wsgi. I tried to added an app to the project and restarted apache and suddenly the project is throwing the error even after undoing the changes. Getting the same error when I'm trying to run python manage.py check:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 284, in execute
self.validate()
File "/usr/lib/python2.7/dist-packages/django/core/management/base.py", line 310, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/dist-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 75, in _populate
self.load_app(app_name, True)
File "/usr/lib/python2.7/dist-packages/django/db/models/loading.py", line 97, in load_app
app_module = import_module(app_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/mezzanine/boot/__init__.py", line 16, in <module>
from django.apps import apps
ImportError: No module named apps
Path to django: "/usr/local/lib/python2.7/dist-packages/django", and it has folder named "apps" and "init.py" file exists inside the folder.
I then created a whole new mezzanine project and ran python manage.py check, and getting the same error. It means not any mezzanine project is working. I tried updating and reinstalling django and mezzanine but no use. On the other hand, a simple django project is running fine.
It seems there is some problem with mezzanine.
I went through the other related questions but couldn't get it resolved. Any help would be much appreciated. Thanks in advance.
You say you have a folder named apps in your Django installation, but the traceback shows it is executing code that was removed in 1.7, the same version that introduced django.apps. Your installation is most likely corrupt and has files from different versions.
Uninstall Django from your Python installation, and completely remove the /usr/local/lib/python2.7/dist-pacakges/django/ folder. Then, reinstall a Django version that is compatible with your version of Mezzanine.
It seems that you've installed Django into your global Python installation. This can easily cause such problems when multiple projects need to use different versions of python packages. It is recommended to use a virtual environment to manage requirements for your projects in an isolated environment and prevent such conflicts.

Error in migration of django app using celery

I'm using celery in my django app. I have setup celery as usual. But, when i try to migrate, it displays error:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/makemigrations.py", line 111, in handle
convert_apps=app_labels or None,
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/autodetector.py", line 42, in changes
changes = self._detect_changes(convert_apps, graph)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/autodetector.py", line 109, in _detect_changes
self.old_apps = self.from_state.render(ignore_swappable=True)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/state.py", line 57, in render
self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps + list(app_labels))])
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 56, in __init__
self.populate(installed_apps)
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: djcelery
Operations to perform:
Synchronize unmigrated apps: djcelery
Apply all migrations: auth, contenttypes, admin, djcelery, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying djcelery.0001_initial...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 161, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 68, in migrate
self.apply_migration(migration, fake=fake)
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 96, in apply_migration
if self.detect_soft_applied(migration):
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 140, in detect_soft_applied
apps = project_state.render()
File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/state.py", line 57, in render
self.apps = Apps([AppConfigStub(label) for label in sorted(self.real_apps + list(app_labels))])
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 56, in __init__
self.populate(installed_apps)
File "/usr/local/lib/python3.4/dist-packages/django/apps/registry.py", line 89, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: djcelery
I'm using django version 1.7.5 and celery version 3.1.17. In the sample code, only djcelery app is added in the app list in settings.py .
I think that I had the same problem. I tried to find duplicate names on installed apps and even modules named djcelery inside other packages. Didn't find anything to help. In my case, the app was running fine in some machines, but was failing in others. I could even make it run, but migrate kept failing.
What solved my problem was to reinstall all my pip packages. Supposing that you have all your packages listed in a file requirements.txt:
pip uninstall -r requirements.txt
and then
pip install -r requirements.txt
I think this problem may be caused by a dead pyc or a bad dependency chain. I also found a problem with mysql for python being installed partially by pip and part by apt-get (running on Ubuntu). You can check this running your command like:
python -m pdb manage.py migrate
The error reported by pdb was related to a bad connection. Without pdb I had the same message as yours.
Tested on Ubuntu with Python 2.7.6, pip 6.1.1, django 1.7, celery 3.1.8, django-celery-3.1.16.
The problem definitely stems from the fact that djcelery appears in both unmigrated and migrated apps. From what I've seen this is usually symptomatic of having both south and django style migrations in the same app. In any case likely something is off with djcelery's migrations directory.

How to translate Django app

I'm trying to add a translation (localization) layer to my appliaction.
I have tried to follow the instructions from: https://docs.djangoproject.com/en/1.7/topics/i18n/translation/#how-to-create-language-files
But I run in some problems when I tried to run
django-admin.py makemessages -l he
In order to create a translation file for Hebrew.
When I first run this code I got the following error:
CommandError: Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed.
So I run the command:
brew install gettext
But I still got an error:
CommandError: Can't find msguniq. Make sure you have GNU gettext tools 0.15 or newer installed.
So I saw in some places that I need to run:
brew link gettext --force
Now when I try to run the command:
django-admin.py makemessages -l he
I get the following error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
pkg_resources.run_script('Django==1.7.1', 'django-admin.py')
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 492, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 1350, in run_script
execfile(script_filename, namespace, namespace)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/EGG-INFO/scripts/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/commands/makemessages.py", line 283, in handle_noargs
potfiles = self.build_potfiles()
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/commands/makemessages.py", line 299, in build_potfiles
file_list = self.find_files(".")
File "/Library/Python/2.7/site-packages/Django-1.7.1-py2.7.egg/django/core/management/commands/makemessages.py", line 358, in find_files
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT)]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/posixpath.py", line 327, in normpath
initial_slashes = path.startswith('/')
AttributeError: 'NoneType' object has no attribute 'starts with'
I'm using a Mac with Django 1.7 and Python 2.7.6
please help to understand what I'm missing
try for instance python ../manage.py makemessages -l en inside your app
django-admin.py didn't work for me either
You should point django to your project's settings.py file.
export DJANGO_SETTINGS_MODULE=/path/to/settings.py

django manage.py migrate raises AttributeError

When I try to migrate my db, I'm getting this error:
Running migrations for easy_thumbnails:
- Nothing to migrate.
- Loading initial data for easy_thumbnails.
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
ignore_ghosts = ignore_ghosts,
File "/Library/Python/2.7/site-packages/south/migration/__init__.py", line 233, in migrate_app
migrator.load_initial_data(target, db=database)
File "/Library/Python/2.7/site-packages/south/migration/migrators.py", line 222, in load_initial_data
self.post_1_6(target, db)
File "/Library/Python/2.7/site-packages/south/migration/migrators.py", line 240, in post_1_6
old_cache = django.db.models.loading.cache
AttributeError: 'module' object has no attribute 'loading'
Apps versions are:
Django 1.6.2
Easy thumbnails 1.4
Mptt 0.5.5
Pymorphy 0.5.6
Python 2.7.5
Pytils 0.3dev
South 0.8.4
Suit 0.2.5
It's looks like not easy_thumbnails problem, because when I try to migrate my django-allauth it raises the same error.
Please, help me!
It seems like your django package was broken. Check that there is python2.7/site-packages/django/db/models/loading.py file in your environment. Or just reinstall django package.
pip install -U --force-reinstall django

Django Local Installation syncdb ImproperlyConfigured

I have been struggling to get a local django installation set up on a mac osx10.6.8. Running syncdb fails to recognize the apps that I have installed.
admins-macbook:myproject Admin$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/Admin/myapp/lib/python2.7/site-packages/south/management/commands/__init__.py", line 10, in <module>
import django.template.loaders.app_directories
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/template/loaders/app_directories.py", line 23, in <module>
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
django.core.exceptions.ImproperlyConfigured: ImportError haystack: cannot import name openProc
I have installed all the apps in the requirements.txt and they exist in the
lib/python2.7/site-packages/
directory. It is on my pythonpath:
admins-macbook:myproject Admin$ echo $PATH
/Users/Admin/myapp/lib/python2.7/site-packages:(... etc.)
How can I properly run syncdb? Thanks for your ideas!
you may installed pip install haystack which is wrong.
you need to install dyango haystack by pip install django-haystack
please refer this SO question

Categories