I am using Django 1.6. I want to start working site. When you use python manage.py shell get an error:
(test) D:\test>python manage.py shell
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "D:\testvenv\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
utility.execute()
File "D:\testvenv\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\testvenv\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "D:\testvenv\lib\site-packages\django\core\management\base.py", line 280, in execute
translation.activate('en-us')
File "D:\testvenv\lib\site-packages\django\utils\translation\__init__.py", line 130, in activate
return _trans.activate(language)
File "D:\testvenv\lib\site-packages\django\utils\translation\trans_real.py", line 188, in activate
_active.value = translation(language)
File "D:\testvenv\lib\site-packages\django\utils\translation\trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "D:\testvenv\lib\site-packages\django\utils\translation\trans_real.py", line 159, in _fetch
app = import_module(appname)
File "D:\testvenv\lib\site-packages\django\utils\importlib.py", line 40, in import_module
__import__(name)
File "D:\testvenv\lib\site-packages\constance\backends\database\__init__.py", line 1, in <module>
from django.core.cache import caches
ImportError: cannot import name caches
Tell me what I have a problem. And if it can depend on your database (not sure that Django is connected to the DB - I do not know how to check)?
Added:
Code manag.py:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
By the looks of it you're using django-constance.
According to their change log, they haven't supported 1.6 since version 1.1
So either use an older version of that, or better yet - use a supported version of django.
According to the release notes, django.core.cache.caches was introduced in Django 1.7, so this application has never worked with Django 1.6.
If you have a running instance of that application, check which version of Django it actually uses.
Related
I'm trying to develop and deploy django app on azure web apps.
While following the tutorial on azure website, after cloning the basic project to my local machine (using git) and creating the virtual environment, I'm trying to run the createsuperuser commend, and getting this error:
C:\Users\tutzy\Desktop\newtest\amir1>env\scripts\python manage.py createsuperuser
Traceback (most recent call last):
File "manage.py", line 17, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 52, in execute
return super(Command, self).execute(*args, **options)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\core\management\base.py", line 413, in execute
translation.activate(saved_locale)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\utils\translation\__init__.py", line 154, in activate
return _trans.activate(language)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\utils\translation\trans_real.py", line 216, in activate
_active.value = translation(language)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\utils\translation\trans_real.py", line 205, in translation
_translations[language] = DjangoTranslation(language)
File "C:\Users\tutzy\Desktop\newtest\amir1\env\lib\site-packages\django\utils\translation\trans_real.py", line 118, in __init__
raise IOError("No translation files found for default language %s." % settings.LANGUAGE_CODE)
IOError: No translation files found for default language en-us.
It seems that your issue was similar with the other SO thread No translation file found for domain 'django' if you clone the Azure offical sample for Django like this. There is a *.mo line at the 49th line of .gitignore file. Please try to add the missing .mo file and do the createsupersuer operation again.
Hope it helps.
Environment :
python 2.7.10
django 1.8.6(copied from site-package folder)
I copied the django distribute into my project folder.
Thinking it will work well
It works perfectly in one of my machine, but throw an error below in another one
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "cmdb_lib/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "cmdb_lib/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "cmdb_lib/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "cmdb_lib/django/core/management/base.py", line 393, in run_from_argv
self.execute(*args, **cmd_options)
File "cmdb_lib/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "cmdb_lib/django/core/management/base.py", line 458, in execute
translation.activate(saved_locale)
File "cmdb_lib/django/utils/translation/__init__.py", line 146, in activate
return _trans.activate(language)
File "cmdb_lib/django/utils/translation/trans_real.py", line 222, in activate
_active.value = translation(language)
File "cmdb_lib/django/utils/translation/trans_real.py", line 206, in translation
_translations[language] = DjangoTranslation(language)
File "cmdb_lib/django/utils/translation/trans_real.py", line 115, in __init__
self._init_translation_catalog()
File "cmdb_lib/django/utils/translation/trans_real.py", line 153, in _init_translation_catalog
translation = self._new_gnu_trans(localedir, use_null_fallback)
File "cmdb_lib/django/utils/translation/trans_real.py", line 136, in _new_gnu_trans
fallback=use_null_fallback)
File "/usr/local/lib/python2.7/gettext.py", line 472, in translation
raise IOError(ENOENT, 'No translation file found for domain', domain)
IOError: [Errno 2] No translation file found for domain: u'django'
But in my settings.py I set LANGUAGE_CODE = 'en-us' as default!
How could this throw an error?
I tried to pip install django, problem solved ,but I still want to include the django package in my project.
How can I achieve this?
I think I got the solution , my .gitignorefile ignored the .mo file , I added it and everything 's OK now
If you are using git, check your .gitignore file and comment*.mo
add the missing .mofile ,and things will be good
I've changed my manage.py and settings.py and added a wsgi.py file to bring my Django 1.4 project closer to the modern age. This was done primarily because django_gunicorn is now deprecated. I'm using Python 2.7.9 and Django 1.4.19 in a PyCharm 4.0.6 development environment.
I also changed my directory structure from flat to nested.
/gse
manage.py
/gse
__init__.py
settings.py
urls.py
wsgi.py
...
/app1
/app2
manage.py
from os import environ
import sys
if __name__ == "__main__":
environ.setdefault("DJANGO_SETTINGS_MODULE", "gse.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gse.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
I installed django-avatar a while back, and now after the changes mentioned above it is breaking when I run manage.py validate.
I get the following traceback in PyCharm:
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 4.0.6\helpers\pycharm\django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "C:\Python27\Lib\runpy.py", line 176, in run_module
fname, loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 82, in _run_module_code
mod_name, mod_fname, mod_loader, pkg_name)
File "C:\Python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\nu\gse\manage.py", line 23, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\__init__.py", line 443, in execute_from_command_line
utility.execute()
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\base.py", line 232, in execute
output = self.handle(*args, **options)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\base.py", line 371, in handle
return self.handle_noargs(**options)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\commands\validate.py", line 9, in handle_noargs
self.validate(display_num_errors=True)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\db\models\loading.py", line 158, in get_app_errors
self._populate()
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name, True)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\db\models\loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\avatar\models.py", line 23, in <module>
avatar_storage = get_storage_class(settings.AVATAR_STORAGE)()
File "C:\Users\nu\gseVirtualEnv\lib\site-packages\django\core\files\storage.py", line 149, in __init__
self.location = abspathu(self.base_location)
File "C:\Users\nu\gseVirtualEnv\lib\ntpath.py", line 487, in abspath
path = _getfullpathname(path)
TypeError: coercing to Unicode: need string or buffer, tuple found
Process finished with exit code 1
I noticed that from django.conf import settings is used in django-avatars conf.py file. I tested the import statement in my project and discovered that PyCharm doesn't seem to be able to list the expected member variables from the settings class when I type settings.. My settings file correctly associated with Django in PyCharm.
Thank you Aamir.
When I looked at settings.py again I saw this:
MEDIA_ROOT = (os.path.join(os.path.dirname(__file__), '..', 'media').replace('\\','/'),)
AVATAR_STORAGE = MEDIA_ROOT + '\avatars'
Changing the MEDIA_ROOT assignment line to:
MEDIA_ROOT = os.path.join(os.path.dirname(__file__), '..', 'media').replace('\\','/')
Fixed it.
I'm learning python + Django by reading 《beginning django e-commerce》, after I have installed django-db-log, when running $python manage.py runserver, there is a problem.
Unhandled exception in thread started by <function wrapper at 0x02C28DB0>
Traceback (most recent call last):
File "D:\Python27\lib\site-packages\django\utils\autoreload.py", line 93, in wrapper fn(*args, **kwargs)
File "D:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 92, in inner_run self.validate(display_num_errors=True)
File "D:\Python27\lib\site-packages\django\core\management\base.py", line 308, in validate num_errors = get_validation_errors(s, app)
File "D:\Python27\lib\site-packages\django\core\management\validation.py", line 34, in get_validation_errors for (app_name, error) in get_app_errors().items():
File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 166, in get_app_errors self._populate() File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 75, in _populate self.load_app(app_name)
File "D:\Python27\lib\site-packages\django\db\models\loading.py", line 96, in load_app models = import_module('.models', app_name)
File "D:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module __import__(name)
File "build\bdist.win32\egg\djangodblog\models.py", line 9, in <module>
File "build\bdist.win32\egg\djangodblog\manager.py", line 23, in <module>
File "build\bdist.win32\egg\djangodblog\helpers.py", line 5, in <module>
ImportError: No module named hashcompat
You are referring to an outdated manual. Module hashcompat was removed in Django 1.6, as you can read here.
Either install an older Django version (1.5 or previous) or get a more recent textbook. You can also manually fix your code by using Python builtins as advised in the removal notice, but for a beginner can be sort of a hassle :)
I solved it using hashlib. I just added:
try:
from hashlib import sha1 as sha_constructor
except ImportError:
from django.utils.hashcompat import sha_constructor
hashcompat is already deprecated in django 1.6, it is better to use hashlib instead
If you are still following that, the django version used in the book is 1.1 and if you are using higher version of django, then try removing the djangodblog from the app list in the setting.py file. It should work.
Like most other Mac/MySQL users with current versions of OS X, I went through the normal issues of getting Python, MySQL and MySQLdb (MySQL-Python) playing nicely together. That has been working for some time, but I'd like to use Aptana for debugging my work Django projects and when I try running either the debugger or running a project, I'm getting the dreaded "mach-o" error.
The interesting thing is that I've configured Aptana to use the same python I'm using (confirmed with a "which python" both within and outside of Aptana), and I've confirmed that the python that's being invoked by Aptana is 32-bit as it should be (same as system terminal reports). Also, when I use the Terminal in Aptana, using the interactive python shell I'm able to successfully 'import MySQLdb'. So I'm stumped.
Under arguments I'm adding this to program arguments per instructions:
runserver 8081 --noreload
But that shouldn't affect anything AFAIK. I'm at a loss of what to do next. Here is the error that Aptana is throwing when I try to launch:
pydev debugger: starting
Validating models...
Traceback (most recent call last):
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.6.0.2012062515/pysrc/pydevd.py", line 1392, in <module>
debugger.run(setup['file'], None, None)
File "/Applications/Aptana Studio 3/plugins/org.python.pydev_2.6.0.2012062515/pysrc/pydevd.py", line 1085, in run
pydev_imports.execfile(file, globals, locals) #execute the script
File "/Users/my/path/project/manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 78, in run
self.inner_run(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/runserver.py", line 88, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/django/db/utils.py", line 33, in load_backend
return import_module('.base', backend_name)
File "/Library/Python/2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Python/2.7/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: dlopen(/Library/Python/2.7/site-packages/_mysql.so, 2): no suitable image found. Did find:
/Library/Python/2.7/site-packages/_mysql.so: mach-o, but wrong architecture
Any ideas?
Take a look at: How do I force Python to be 32-bit on Snow Leopard and other 32-bit/64-bit questions on ways to configure Python to run in 32 bits (VERSIONER_PYTHON_PREFER_32_BIT environment variable seems a good choice).
Or maybe:
Troubles with PyDev and external libraries in OS X