I recently have downloaded a django project off of github (it is confidential so I cannot share the code). And I am writing a script that should be processing some of the models. I changed the correct information in the settings and have created my basic script for testing that looks like the this:
from appname.models import *
print "hello world"
When I try python manage.py shell < script.py I get ImportError: No module named chosen. Why is this and what can I do to get my script to run?
here is the full traceback:
Setting Django settings
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.6-py2.7.egg/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/Library/Python/2.7/site-packages/Django-1.6-py2.7.egg/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named chosen
Maybe the "chosen" django plugin needs to be installed.
Related
I am currently working with a project that requires import an excel file into Django database. I googled it and found out that django-import-export package is exactly what I want.
However, when I import "import_export" into my "settings.py" or "from import_export.admin import ImportExportModelAdmin" into my "admin.py", the error appears although I have successfully installed this package. I have also followed the tutorial here, but the result is still the same.
Is there any way to solve this problem or any suggestions? Could you please help me? Thanks in advance!
Here is the code from a tutorial on youtube that I used for testing:
/*admin.py*/
from django.contrib import admin
# Register your models here.
from .models import *
from import_export.admin import ImportExportModelAdmin
#admin.register(Laptop, Desktop, Mobile)
class ViewAdmin(ImportExportModelAdmin):
pass
/*settings.py*/
INSTALLED_APPS = [
...
'import_export',
]
/*After running python manage.py runserver */
Watching for file changes with StatReloader
Performing system checks...
Traceback (most recent call last):
File "manage.py", line 24, in <module>
main()
File "manage.py", line 20, in main
execute_from_command_line(sys.argv)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\__init__.py", line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\base.py", line 328, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\base.py", line 369, in execute
output = self.handle(*args, **options)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\commands\runserver.py", line 95, in handle
self.run(**options)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\core\management\commands\runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 599, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 584, in start_django
reloader.run(django_main_thread)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 299, in run
self.run_loop()
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 305, in run_loop
next(ticker)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 345, in tick
for filepath, mtime in self.snapshot_files():
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 361, in snapshot_files
for file in self.watched_files():
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 260, in watched_files
yield from iter_all_python_module_files()
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 105, in iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\django\utils\autoreload.py", line 118, in iter_modules_and_files
if module.__name__ == '__main__':
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\py\_apipkg.py", line 171, in __getattribute__
return getattr(getmod(), name)
File "C:\FWTools\WinPython-201702\python-3.6.2\lib\site-packages\py\_error.py", line 44, in __getattr__
raise AttributeError(name)
AttributeError: __name__
I suggest you get the example application working first.
Clone repo from github
Install dependencies into a virtual env (e.g. pip install -r requirements/test.txt)
Follow these instructions to install and load the example app.
Once you have the example application running, you have the basis for developing your own.
I have a Django (version 1.9) application running with python 2.7.10 and I'm using Virtualenv.
Running the application with ./manage.py runserver I've no error, but when I try to run in debug I get django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Here is the Pycharm debugging configuration:
Any idea why?
Here is the complete stack trace:
/Users/matteobetti/Progetti/Enydros/enysoft/bin/python ./manage.py runserver
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 176, in fetch_command
commands = get_commands()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/utils/lru_cache.py", line 100, in wrapper
result = user_function(*args, **kwds)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/core/management/__init__.py", line 71, in get_commands
for app_config in reversed(list(apps.get_app_configs())):
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 137, in get_app_configs
self.check_apps_ready()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 124, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
I add import django e django.setup before execute_from_command_line(sys.argvs)
and I get this stack trace:
Traceback (most recent call last):
File "/Users/matteobetti/Progetti/Enydros/enysoft/manage.py", line 10, in <module>
django.setup()
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/apps.py", line 2, in <module>
from frontend.services.container import app_context
File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/services/container.py", line 1, in <module>
from frontend.services.enysoft_services import RService, FixedSizeDirectoryCache, TubeSectionService, CsvSanifier
File "/Users/matteobetti/Progetti/Enydros/enysoft/frontend/services/enysoft_services.py", line 5, in <module>
import rpy2.robjects as ro
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/rpy2/robjects/__init__.py", line 15, in <module>
import rpy2.rinterface as rinterface
File "/Users/matteobetti/Progetti/Enydros/enysoft/lib/python2.7/site-packages/rpy2/rinterface/__init__.py", line 16, in <module>
tmp = subprocess.check_output(("R", "RHOME"), universal_newlines=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Another thing to say is that my colleagues with Linux have no problem with the same virtualenv configuration, the only one that has a problem is me, using MacOs.
Try to add you settings file to system PATH. In my projects settings are in the folder /project_name/project_name/settings/development.py (that is slightly different from standard way). And in my case Evironment variables string is
DJANGO_SETTINGS_MODULE=project_name.settings.development;PYTHONUNBUFFERED=1
So change it according to your parameters and then try to run server again. I hope this helps.
I use ubuntu and I installed the django debug toolbar with pip using sudo pip install django-debug-toolbar. Then I added it to my settings file. Now when I start the django app server I get this error message.
Traceback (most recent call last):
File "./social/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/dac/.virtualenvs/kthsocial/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/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named debug_toolbar
(kthsocial)dac#dac-VPCSA2Z9E:/etc/social/social$ ./social/manage.py runserver
Traceback (most recent call last):
File "./social/manage.py", line 16, in <module>
execute_from_command_line(sys.argv)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/home/dac/.virtualenvs/kthsocial/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/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/home/dac/.virtualenvs/kthsocial/local/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named debug_toolbar
Why doesn't it work?
This is because sudo pip install django-debug-toolbar never installed django-debug-toolbar in your virtualenv. Make sure your virtualenv is activate and use pip install django-debug-toolbar. Don't use sudo
Don't use sudo to install things when you're in a virtualenv.
I´m having a issue when I ran "python manage.py rebuild_index" in my app supported by haystack and elasticsearch.
Python 2.7
Django version 1.6.2
Haystack 2.1.0
Elasticsearch 1.0
Please see the error that is appearing:
Traceback (most recent call last):
File "manage.py", line 10, in
execute_from_command_line(sys.argv)
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/base.py", line 242, in >run_from_argv
self.execute(*args, **options.dict)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 15, in handle
call_command('clear_index', **options)
File "/usr/lib/python2.7/site-packages/django/core/management/init.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/lib/python2.7/site-packages/haystack/management/commands/clear_index.py", line 48, in handle
backend = connections[backend_name].get_backend()
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 98, in getitem
self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 51, in load_backend
return import_class(full_backend_path)
File "/usr/lib/python2.7/site-packages/haystack/utils/loading.py", line 18, in import_class
module_itself = importlib.import_module(module_path)
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
import(name)
File "/usr/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 21, in
raise MissingDependency("The 'elasticsearch' backend requires the installation of 'requests'.")
haystack.exceptions.MissingDependency: The 'elasticsearch' backend requires the installation of 'requests'.
I've installed all the packages needed to run those apps however is asking about requests, What is it about?
just do
pip install pyelasticsearch
If you just install requests module through pip this error should go away.
I'm trying to create and run a project.
I used the following article:
https://docs.djangoproject.com/en/dev/intro/tutorial01/?from=olddocs
When I'm running the following command
C:\django\mysite>python manage.py runserver
This error shows up:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 438, in execute_manager
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django\contrib\staticfiles\management\commands\runserver.py", line 4, in <module>
from django.core.management.commands.runserver import BaseRunserverCommand
File "C:\Python27\lib\site-packages\django\core\management\commands\runserver.py", line 8, in <module>
from django.core.handlers.wsgi import WSGIHandler
File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 10, in <module>
from django import http
File "C:\Python27\lib\site-packages\django\http\__init__.py", line 117, in <module>
from django.core import signing
ImportError: cannot import name signing
Here is what I would do.
Try to use virtualenv.
there might be some old python modules that mess up your django for some reason.
So use virtualenv to create a fresh python.
and install django with pip install.
if it solves the problem its definetely your system python that is messing things up a little bit.