python elastic search not working pyes package issues - python

Installed pyes recently , but when i tired it in the python shell it is giving the error,
Can any one please help me out in this regard:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pyes-0.19.1-py2.7.egg/pyes/__init__.py", line 41, in <module>
from .djangoutils import *
File "/usr/local/lib/python2.7/dist-packages/pyes-0.19.1-py2.7.egg/pyes/djangoutils.py", line 6, in <module>
from django.db import models
File "/usr/local/lib/python2.7/dist-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 52, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 45, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

I found that this issue can be "worked around" by simply performing the following before running the script in Terminal
export DJANGO_SETTINGS_MODULE=default.settings
After running that code the script worked exactly the way it was supposed to!

Related

Django 2.0 Tutorial - Cant Acess Django-Admin Shell

When I attempt to acess the Django Shell using Django-Admin Shell, I get the error message:
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
(env2) Coreys-MacBook-Pro:mysite3 coreydickinson$
I've attempted the settings.configure() in the python shell, and I'ved tried redirecting the Django settings using django-admin.py shell --settings=mysite.settings. Neither worked. Anyone have any idea what I am doing wrong?
Full error:
(env2) Coreys-MacBook-Pro:mysite3 coreydickinson$ django-admin shell
Traceback (most recent call last):
File "/Users/coreydickinson/mysite/DJDev/env2/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/core/management/__init__.py", line 371, in execute_from_command_line
utility.execute()
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/core/management/__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/core/management/base.py", line 327, in execute
saved_locale = translation.get_language()
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/utils/translation/__init__.py", line 187, in get_language
return _trans.get_language()
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/utils/translation/__init__.py", line 55, in __getattr__
if settings.USE_I18N:
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/coreydickinson/mysite/DJDev/env2/lib/python3.6/site-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting USE_I18N, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
(env2) Coreys-MacBook-Pro:mysite3 coreydickinson$
You are supposed to use manage.py, not django-admin.py.

issue with create_user.py in django-cms

I just started using django-cms and am facing issues. I used virtualenv.please help.The following is the error:
Traceback (most recent call last):
File "create_user.py", line 4, in <module>
from django.contrib.auth import get_user_model
File "/home/mayankmodi/SSAD18/Source/env/local/lib/python2.7/site-packages
/django/contrib/auth/__init__.py", line 7, in < module>
from django.middleware.csrf import rotate_token
File "/home/mayankmodi/SSAD18/Source/env/local/lib/python2.7/site-packages
/django/middleware/csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "/home/mayankmodi/SSAD18/Source/env/local/lib/python2.7/site-packages/django/utils/cache.py", line 26, in <module>
from django.core.cache import caches
File "/home/mayankmodi/SSAD18/Source/env/local/lib/python2.7/site-packages/django/core/cache/__init__.py", line 34, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/home/mayankmodi/SSAD18/Source/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/mayankmodi/SSAD18/Source/env/local/lib/python2.7/site-packages
/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Can somebody tell me which specific files to edit and what edits should i make
Try running this command instead:
djangocms -w web
This will start the djangocms-installer wizard and run you through various settings, dependencies, and create a superuser for you to log in with. When it finishes, you should have a running instance of django-cms within ./web/.
You can access the new instance by going into ./web/ and running runserver as usual:
$ source venv/bin/activate
(venv) $ python manage.py runserver
I have same problem from a few week ago. I assume the new version(djangocms-installer==0.9.x) have problem because when I created a project using default djangocms-installer(==0.9.0) like "djangcms -p . mysite", there was no questions about DB, django version, or etc, then error...
Try old version "pip install djangocms-installer==0.8.x"(x=12,11,10,...)
Now, I am using "djangocms-installer==0.8.12" without any error.

Django Tutorial Error: Setting up the test client

I'm on part 5 of the Django Tutorial and I've hit a snag. I'm trying to setup the test client with the following commands in the python shell:
from django.test.utils import setup_test_environment
setup_test_environment()
I get the following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/mohitgupta/.virtualenvs/Django/lib/python2.7/site-packages/django/test/utils.py", line 104, in setup_test_environment
mail._original_email_backend = settings.EMAIL_BACKEND
File "/Users/mohitgupta/.virtualenvs/Django/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
self._setup(name)
File "/Users/mohitgupta/.virtualenvs/Django/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_BACKEND, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I've looked into defining the DJANGO_SETTINGS_MODULE with no real progress. Just a note that I'm using PyCharm as an IDE but I don't use the internal terminal they provide.
Any suggestions?
As mentioned in previous sections of the tutorial, to start a shell in Django you should always do ./manage.py shell, rather than starting Python directly. That sets up the environment for you.
I had a similar problem and it worked after I gave the command in the shell
import django
django.setup()

Python Django Error on local in windows

i found an error while running webservice on local
Traceback (most recent call last):
File "D:\Projects\wamp\www\mysite_livebackupcode\django-apps\mysite\account\views.py", line 3, in <module>
from django.views.decorators.csrf import csrf_exempt
File "C:\Python27\Lib\site-packages\django\views\decorators\csrf.py", line 1, in <module>
from django.middleware.csrf import CsrfViewMiddleware, get_token
File "C:\Python27\Lib\site-packages\django\middleware\csrf.py", line 14, in <module>
from django.utils.cache import patch_vary_headers
File "C:\Python27\Lib\site-packages\django\utils\cache.py", line 26, in <module>
from django.core.cache import get_cache
File "C:\Python27\Lib\site-packages\django\core\cache\__init__.py", line 69, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "C:\Python27\Lib\site-packages\django\conf\__init__.py", line 54, in __getattr__
self._setup(name)
File "C:\Python27\Lib\site-packages\django\conf\__init__.py", line 47, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either
define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
can anybody please help me to get out of this stuff.
thanks in advance
You can set environment variable in linux for example:
export DJANGO_SETTINGS_MODULE=myproject.settings
It should help you.

Python error in virtuaenv

I have a script, which should run once per day by crontab. That works fine on my desktop. But when I try to run it on a virtualenv on my RPi, I get this error:
Traceback (most recent call last):
File "mailalert.py", line 7, in <module>
from django.contrib.auth.models import User
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/contrib/auth/__init__.py", line 5, in <module>
from django.middleware.csrf import rotate_token
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/middleware/csrf.py", line 16, in <module>
from django.utils.cache import patch_vary_headers
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/utils/cache.py", line 26, in <module>
from django.core.cache import get_cache
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/core/cache/__init__.py", line 70, in <module>
if DEFAULT_CACHE_ALIAS not in settings.CACHES:
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
It looks like I cant use:
from django.contrib.auth.models import User
What is the problem?
DJANGO_SETTINGS_MODULE
You need to configure the DJANGO_SETTINGS_MODULE environment variable in your mailalert.py script, prior to importing Django code.
Here's how you could do it:
#!/usr/bin/env python
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "benchmarks.settings")
# Do you thing now.
Virtualenv
Note that you code is probably not running inside a virtualenv right now, as made evidenced by the package paths (/usr/local/lib isn't your virtualenv):
"/usr/local/lib/python2.7/dist-packages/Django-1.5.4-py2.7.egg/django/contrib/auth/__init__.py"

Categories