I'm getting the following error when trying to run
django-admin runserver
PS C:\Users\gasgu\PycharmProjects\djangodennisproj\devsearch> django-admin runserver
Traceback (most recent call last):
File "C:\Users\gasgu\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\gasgu\AppData\Local\Programs\Python\Python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\gasgu\PycharmProjects\djangodennisproj\venv\Scripts\django-admin.exe\__main__.py", line 7, in <module>
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\core\management\__init__.py", line 419, in execute_from_command_line
utility.execute()
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\core\management\__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\core\management\base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute
super().execute(*args, **options)
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\core\management\base.py", line 398, in execute
output = self.handle(*args, **options)
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\core\management\commands\runserver.py", line 68, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\conf\__init__.py", line 82, in __getattr__
self._setup(name)
File "c:\users\gasgu\pycharmprojects\djangodennisproj\venv\lib\site-packages\django\conf\__init__.py", line 63, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
I have done a clean installation with a virtualenv, then I didi pip install django, created the project and do the runserver.
I'm running this from pycharm community and I read that I should also set an enviroment variable called DJANGO_SETTINGS_MODULE and I should put my project.settings as value. I did that and I still get the error.
I've also tried the same process from outside pycharm and just with command line I still get the same error. is there something I'm doing wrong?
Also as a note: if I do "python manage.py runserver" it does start the server. but I don't know if this is the way it should be done.
your should always use the manage.py utility after first creating the project with django-admin, basically they are the same thing but manage.py have the setting/configurations for that project..so issues like this can be avoided. if your aim of using it is more specific..please notify
Related
For some reasons, I had to reinstall Python on my desktop. Since then, my django applications are not working. I can create one, but as soon as I import a package anywhere in the application, I can't run python manage.py runserver
I can run another python script, I can start Jupyter Notebooks (and import the exact same packages in them). I also tried to create new projects with the "new" python installed, as soon as I add import pandas (or any other packages except django), I have the error.
The error message is quite long :
Watching for file changes with StatReloader
Performing system checks...
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 585, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 570, in start_django
reloader.run(django_main_thread)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 288, in run
self.run_loop()
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 294, in run_loop
next(ticker)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 334, in tick
for filepath, mtime in self.snapshot_files():
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 350, in snapshot_files
for file in self.watched_files():
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 249, in watched_files
yield from iter_all_python_module_files()
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 103, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\djan
go\utils\autoreload.py", line 116, in iter_modules_and_files
if module.__name__ == '__main__':
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\py\_
apipkg.py", line 171, in __getattribute__
return getattr(getmod(), name)
File "C:\Users\MyName\AppData\Local\Continuum\anaconda3\lib\site-packages\py\_
error.py", line 44, in __getattr__
raise AttributeError(name)
AttributeError: __name__
Got this annoying error after aborting an IDE-refactoring.
I suggest the following to reproduce the problem:
Revert git changes.
Make sure there are no cyclic imports in your code.
Reinstall virtual environment.
Unfortunately the error was still there in my case. So I knew the problem must be with python. And indeed:
Reinstalling python 3.7 solved the problem.
Did you pip install django?
I think when you reinstalled Python you didn't installed packaged like Django
Uninstall the current Django package and install Django 2.1.5
Use this command on windows:
pip install --user django==2.1.5
Every time I open a new shell, I get this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/virtualenvwrapper/hook_loader.py", line 223, in <module>
main()
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/virtualenvwrapper/hook_loader.py", line 132, in main
run_hooks(hook, options, args)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/virtualenvwrapper/hook_loader.py", line 161, in run_hooks
hook_mgr = ExtensionManager(namespace)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/stevedore/extension.py", line 106, in __init__
verify_requirements)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/stevedore/extension.py", line 179, in _load_plugins
for ep in self.list_entry_points():
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/stevedore/extension.py", line 168, in list_entry_points
eps = list(pkg_resources.iter_entry_points(self.namespace))
AttributeError: module 'pkg_resources' has no attribute 'iter_entry_points'
virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader,
check that virtualenvwrapper has been installed for
VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.5 and that PATH is
set properly.
Oddly enough, virtualenvwrapper is still working fine. If I try to activate a virtualenv, it spits out this error again, but the environment does load up. This was after I recently tried to clean up my Python versions on my Mac, but I clearly messed up some path.
Let me know if more info is needed.
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.
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
After I solve the issue with "image not found" when I run python manage.py syncdb by adding "export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/" into .bash_profile.
The problem comes with python manage.py runserver
Does anyone know how to solve OSError(Errno 20)?
System check identified no issues (0 silenced).
October 07, 2014 - 18:19:56
Django version 1.8, using settings 'dbtest.settings'
Starting development server at http:/127.0.0.1:8000/
Quit the server with CONTROL-C.
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-1.8-py2.7.egg/django/core/management/__init__.py", line 330, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/__init__.py", line 322, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/base.py", line 363, in run_from_argv
self.execute(*args, **cmd_options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/base.py", line 412, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/commands/runserver.py", line 80, in handle
self.run(**options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/core/management/commands/runserver.py", line 89, in run
autoreload.main(self.inner_run, None, options)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 320, in main
reloader(wrapped_main_func, args, kwargs)
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 286, in python_reloader
reloader_thread()
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 262, in reloader_thread
change = fn()
File "/Library/Python/2.7/site-packages/Django-1.8-py2.7.egg/django/utils/autoreload.py", line 200, in code_changed
stat = os.stat(filename)
OSError: [Errno 20] Not a directory: '/Library/Python/2.7/site-packages/MySQL_python-1.2.3-py2.7-macosx-10.9-intel.egg/MySQLdb/converters.py'
I just realize that I install both mysql-python and mysql-connector-python packages.
By changing the database 'ENGINE' setting from 'django.db.backends.mysql' to 'mysql.connector.django', the issue is solved.
Lesson learned here: I should probably use virtualenv to try different python package.