Improperly configured error when running django-admin check - django

I'm relatively new to Django and programming, so I have no idea what caused this error or how to fix it. I asked another question related to the same error but got no responses so here's a simpler version.
When I run Django-admin check (along with various other commands not including run server) I get the following error.
django.core.exceptions.ImproperlyConfigured: Requested setting LANGUAGE_CODE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I have spent hours googling and nothing I find works (I either get this error or a module not found error). What can I do?
here's the full traceback:
Traceback (most recent call last):
File "/Users/linnea/opt/miniconda3/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
utility.execute()
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 330, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 371, in execute
output = self.handle(*args, **options)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/commands/check.py", line 69, in handle
databases=options['databases'],
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/management/base.py", line 396, in check
databases=databases,
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/checks/registry.py", line 70, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/core/checks/translation.py", line 60, in check_language_settings_consistent
get_supported_language_variant(settings.LANGUAGE_CODE)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/conf/__init__.py", line 83, in __getattr__
self._setup(name)
File "/Users/linnea/opt/miniconda3/lib/python3.7/site-packages/django/conf/__init__.py", line 68, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting LANGUAGE_CODE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Edit: I get the module not found error (no module named ) when I set the Django settings module

The problem is that Django cannot find your settings.py file to run the app. You need to set the environment variable DJANGO_SETTINGS_MODULE to point to you settings.py or if you're using an IDE just add it to your project config.

Related

ValueError: path is on mount 'C:', start on mount 'F:' while django migrations in windows

I am trying to run the following command
python manage.py makemigrations
But, getting the error
ValueError: path is on mount 'C:', start on mount 'F:'
What can be the reason?
complete traceback:-
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 294, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\base.py", line 345, in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 189, in handle
self.write_migration_files(changes)
File "C:\Python34\lib\site-packages\django\core\management\commands\makemigrations.py", line 207, in write_migration_files
migration_string = os.path.relpath(writer.path)
File "C:\Python34\lib\ntpath.py", line 579, in relpath
raise ValueError(error)
ValueError: path is on mount 'C:', start on mount 'F:'
The error is occurring because Django is trying to find a relative path between 2 directories and they do not exist (since they are on different drives). This issue is mentioned here: https://bugs.python.org/issue7195. But this response helps to understand the problem: https://bugs.python.org/msg94780.
os.relpath does give you a relative path between two directories.
The problem you are encountering is that, on Windows, a relative path
doesn't even exist if the two directories are on different drives
(which is exactly what the error message says).
When I ran into this error, I was trying to make a migration file for my own app that is located on the F: drive. Running:
python.exe .\manage.py makemigrations
had Django scanning for every change. It located a change for djcelery. This is located in a virtual environment on my C: drive.
To fix this, I just added the app name when calling makemigrations:
python.exe .\manage.py makemigrations <<app_name>>

Why am I getting errors when trying to invoke Django Python shell?

My current version of python is 2.7.10 and version of Django is 1.9.1, path.py is 8.1.2 but every time when I'm trying to invoke python shell by command:
$ python manage.py shell I'm getting a lot of errors and the ending of them looks like:
Error in sys.excepthook:
Traceback (most recent call last):
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\CrashHandler.py", line 157, in __call__
report.write(self.make_report(traceback))
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\CrashHandler.py", line 215, in make_report
rpt_add('BZR revision : %s \n\n' % Release.revision)
AttributeError: 'module' object has no attribute 'revision'
Original exception was:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\__init__.py", line 353, in execute_from_command_line
utility.execute()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\base.py", line 399, in execute
output = self.handle(*args, **options)
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 69, in handle
self.run_shell(shell=options['interface'])
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 58, in run_shell
return getattr(self, shell)()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 41, in ipython
ip()
File "W:\SVN\vendors\python\win32\lib\site-packages\django\core\management\commands\shell.py", line 22, in _ipython_pre_011
shell = IPShell(argv=[])
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\Shell.py", line 73, in __init__
debug=debug,shell_class=shell_class)
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\ipmaker.py", line 521, in make_IPython
IP.pre_config_initialization()
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\iplib.py", line 835, in pre_config_initialization
self.db = pickleshare.PickleShareDB(rc.ipythondir + "/db")
File "W:\SVN\vendors\python\win32\lib\site-packages\IPython\Extensions\pickleshare.py", line 53, in __init__
if not self.root.isdir():
TypeError: _isdir() takes exactly 1 argument (0 given)
How can I overcome the problem?
From doing a quick search, it looks like this error happens when both Django and IPython are installed, since apparently Django will attempt to use the IPython shell.
The first resource with someone who had a similar issue:
run python manage.py shell occurs errors
And in the link above, one of the comments on the OP's question suggested looking at this separate thread for answers:
https://superuser.com/questions/318655/error-running-ipython3-on-xp-typeerror-isdir-takes-exactly-1-argument-0-gi
The winning answer says the following:
Finally decided to give this another stab, and managed to get it to
work. The solution is a two-line change in the
ipython-0.11-py3.2.egg\IPython\utils\pickleshare.py file, line 52:
Before:
if not self.root.isdir():
self.root.makedirs()
After:
if not os.path.isdir(self.root):
os.makedirs(self.root)

DJANGO_PATH errors and settings issues

I recently upgraded my Ubuntu to 14.04, and consulted this question to solve my erros, ImportError: No module named _io in ubuntu 14.04. That was solved perfectly.
I also checked out this question as it's similar to mine, Consistently getting ImportError: Could not import settings 'myapp.settings' error, but could not use the same solution.
I do not use manage.py in my project and I have done numerous exports of the PYTHON_PATH to no end of my issues. Here is my traceback;
Traceback (most recent call last):
File "/home/thabang/.virtualenvs/lottostar/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/thabang/.virtualenvs/lottostar/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/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/home/thabang/.virtualenvs/lottostar/local/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'lottostar.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named lottostar.settings
I found the problem:
The was an issue with the egg files during the virtualenv reinstall. Though the programs were there, they couldn't be found. I just performed another install of the requirements to refresh the egg info.

"'django_mongodb_engine' isn't an available database backend" when pushing to Heroku

I have a Django app that successfully ran on Heroku and uses mongodb engine. All of a sudden, I can not push it anymore. It does not seem to recognize the django_mongodb_engine module anymore. I even reverted all changes to the version that last ran, but it's still the same. I suspect a version conflict or so, but can not figure out how to fix it.
This is the error I'm getting:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
backend = load_backend(db['ENGINE'])
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/utils.py", line 51, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named utils
And these are the important parts from the requirements.txt:
hg+https://bitbucket.org/wkornewald/django-nonrel
git+https://github.com/django-nonrel/mongodb-engine
hg+https://bitbucket.org/wkornewald/djangotoolbox
pymongo==2.2.1
pytz==2012d
I'm especially confused because I reverted all changes. Exactly this code with the same configuration ran perfectly (and still does on my production server), just pushing does not work.
Thanks
Simon
Of course, just when I asked on SO I figure out the answer :-)
I don't know why exactly, but defining the exact revision that i want to check out solved the problem.
So the requirements.txt looks now like this:
-e hg+http://bitbucket.org/wkornewald/django-nonrel#be48c152abc6b15e45155e2bbcfd69c665ccb536#egg=Django-dev
-e git+https://github.com/django-nonrel/mongodb-engine#52257b5d90dcfaa564e708264a9cfe591d301fe6#egg=django_mongodb_engine-dev
-e hg+https://bitbucket.org/wkornewald/djangotoolbox#a8cdf61ba9c0cdc7cbbbd37d693e9a222d9a8e5f#egg=djangotoolbox-dev
pymongo==2.2.1
pytz==2012d

PyCharm manage.py runserver error

Sorry to ask a noob question but I have no idea why this is happening.
I've just reinstalled Django 1.3, and am trying PyCharm for the first time. When I run python manage.py runserver from Terminal everything goes without a hitch, however if I try to runserver from within PyCharm I get the following:
Importing Django settings module settings
Traceback (most recent call last):
Validating models...
0 errors found
Django version 1.3, using settings 'glist.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
File "/Applications/PyCharm 1.2.1.app/helpers/pycharm/django_manage.py", line 19, in <module>
run_module(manage_file, None, '__main__')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 180, in run_module
fname, loader, pkg_name)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/Users/goon/code/glist/manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 67, in handle
self.run(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 76, in run
autoreload.main(self.inner_run, args, options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 131, in main
reloader(main_func, args, kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 104, in python_reloader
reloader_thread()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 83, in reloader_thread
ensure_echo_on()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/autoreload.py", line 77, in ensure_echo_on
attr_list = termios.tcgetattr(fd)
termios.error: (25, 'Inappropriate ioctl for device')
Process finished with exit code 1
Please note that this is all happening before I request any page from within the browser. And, as I said, I have no trouble running from Terminal. Any help would be greatly appreciated.
What version fo pycharm are you using ? Actually it`s a error in django 1.3. It will occur if you try to run django from any ide in reload mode. It can be fixed by patching django. Although PyCharm should automatically switch to no reload mode.
Read this : http://blogs.jetbrains.com/pycharm/2011/03/pycharm-1-2-1-release-candidate-py-test-2-0-buildout-1-5/
Apply the patch. Its Django 1.3.1 error. This worked for me on pYCharm 3.4.1
https://github.com/django/django/commit/3e7ce3c750