django-admin.py is blocked by exporting myapp.settings - django

I've exported some settings by mistake, like:
export DJANGO_SETTINGS_MODULE=example.settings
Now when i try to use django-admin.py it gives me error:
Traceback (most recent call last):
File "/usr/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
commands = get_commands()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/usr/lib/python2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'example.settings.base' (Is it on sys.path? Is there an import error in the settings file?): No module named example.settings.base
I've found command called flush, but django-admin is blocked and i don't know what to do, probably i need to find sys.path file.
Thanks in advance!

Related

Import by fileName is not supportted

I have a django project and a dump.json file in which all the database dump is present.
I am trying to run this command to load data into my django project
django-admin loaddata dumpdata.json --settings=~/Workspace/odx-lm/lm/settings/local.py
On running the above command from the folder ~/Workspace/odx-lm/,
I am getting the following error:
Traceback (most recent call last): File
"/home/delhivery/Workspace/odx-lm/odx-lm-env/bin/django-admin.py",
line 5, in
management.execute_from_command_line() File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/core/management/init.py",
line 367, in execute_from_command_line
utility.execute() File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/core/management/init.py",
line 316, in execute
settings.INSTALLED_APPS File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/conf/init.py",
line 53, in getattr
self._setup(name) File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/conf/init.py",
line 41, in _setup
self._wrapped = Settings(settings_module) File "/home/delhivery/Workspace/odx-lm/odx-lm-env/local/lib/python2.7/site-packages/django/conf/init.py",
line 97, in init
mod = importlib.import_module(self.SETTINGS_MODULE) File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name) ImportError: Import by filename is not supported.
Any help would be highly appreciated.
The value for settings must be a Python module path, not a file path.
... --settings=lm.settings.local

I'm getting an error while creating Python Django Project

C:\Python27\Scripts>django-admin startproject python_tutorial
Traceback (most recent call last):
File "c:\python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\Scripts\django-admin.exe\__main__.py", line 9, in <module>
File "c:\python27\lib\site-packages\django\core\management\__init__.py", line 367, in execute_from_command_line
utility.execute()
File "c:\python27\lib\site-packages\django\core\management\__init__.py", line 316, in execute
settings.INSTALLED_APPS
File "c:\python27\lib\site-packages\django\conf\__init__.py", line 53, in __getattr__
self._setup(name)
File "c:\python27\lib\site-packages\django\conf\__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "c:\python27\lib\site-packages\django\conf\__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "c:\python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: Import by filename is not supported.
Can someone please suggest what to do?
By mistake I have set variable "DJANGO_SETTINGS_MODULE" to python path and it messed up. I have deleted this environment variable and it works.

pkg_resources.DistributionNotFound: Django==1.8.3 in Django 1.9

I use Django 1.9 after updating of Django 1.8, and when i type command
django-admin runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 5, in <module>
from pkg_resources import load_entry_point
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2749, in <module>
working_set = WorkingSet._build_master()
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 446, in _build_master
return cls._build_from_requirements(__requires__)
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 459, in _build_from_requirements
dists = ws.resolve(reqs, Environment())
File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 628, in resolve
raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: Django==1.8.3
And then I try to type this one command:
django-admin.py runserver
I got this one error:
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 195, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 39, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 16, in <module>
from django.db.migrations.executor import MigrationExecutor
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 7, in <module>
from .loader import MigrationLoader
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 10, in <module>
from django.db.migrations.recorder import MigrationRecorder
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 12, in <module>
class MigrationRecorder(object):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 26, in MigrationRecorder
class Migration(models.Model):
File "/usr/local/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 27, in Migration
app = models.CharField(max_length=255)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 1072, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py", line 166, in __init__
self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I try uninstall and install Django. But i still have this errors. Hope somebody can help me with it. Thanks
You shouldn't normally use django-admin, except when you do django-admin startproject.
After you have created the project, it is easier to use manage.py to run the dev server, because it takes care of setting the path and settings module for you.
./manage.py runserver
See the docs for more information.
Maybe you used another python version? It is python 2.7 now, and it seems you don't installed django properly for python2.7. You can try
python3 manage.py runserver
for using python3 in ubuntu (it is installed by default and accessibler with python3), or try to define how to run it with another python version.

Running Django Project locally: cannot import settings module

I am trying to work on a friend's Django project. I've cloned his repo, and am having trouble running the project locally.
When I run
python manage.py runserver
I get
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named settings
I am unsure if I am running into a problem because I have conflicting versions of Python installed, but I am unsure of how to proceed. Any advice would be much appreciated.
Thanks

django tutorial/app - error when running python manage.py sql polls

Any help would be greatly appreciated. I'm getting this error and not sure how to fix.
C:\dj_stuff\mysite> python manage.py sql polls
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 453, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 263, in fetch_command
app_name = get_commands()[subcommand]
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 53, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 132, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\dj_stuff\mysite\mysite\settings.py", line 127
) 'polls',
^
SyntaxError: invalid syntax
please paste settings.py.
lines from 100 to 130
but... look at this line:
) 'pools',
you've added appname after tuple.
you should add 'pools' one line upper, before ')'