I would like to use Django to create an app but got an error
"ImportError: No module named books.apps" after running:
python manage.py startapp books
Error message:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/core/management/__init__.py", line 324, in execute
django.setup()
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Library/Python/2.7/site-packages/Django-1.9-py2.7.egg/django/apps/config.py", line 116, in create
mod = import_module(mod_path)
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named books.apps
Any idea what went wrong? Thanks!
You must first start a project before trying to start an app. First run:
python manage.py startproject mysite
and replace "mysite" with what you want to call your project. Then run:
python manage.py startapp books
See the docs here.
Related
Just upgraded from django 1.8 to 1.9 and getting this error while migrating:
Error importing devserver module devserver.modules.sql: "cannot import name util"
Although they say it is fixed it here:
https://github.com/dcramer/django-devserver/issues/131
[localhost] local: python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/halit/project_folder/.venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/halit/project_folder/.venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 324, in execute
django.setup()
File "/home/halit/project_folder/.venv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/halit/project_folder/.venv/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/halit/project_folder/.venv/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/halit/project_folder./venv/local/lib/python2.7/site-packages/devserver/models.py", line 40, in <module>
load_modules()
File "/home/halit/project_folder/.venv/local/lib/python2.7/site-packages/devserver/models.py", line 25, in load_modules
raise exceptions.ImproperlyConfigured, 'Error importing devserver module %s: "%s"' % (name, e)
django.core.exceptions.ImproperlyConfigured: Error importing devserver module devserver.modules.sql: "cannot import name util"
Fatal error: local() encountered an error (return code 1) while executing 'python manage.py migrate'
Aborting.
I was having the same problem. Editing the usr/local/lib/python2.7/dist-packages/devserver/modules/sql.py file and changing the import on line 15 from:
from django.db.backends import util
to
from django.db.backends import utils
Seemed to do it. I had to change all the references in the file from util to utils.
I need to edit but first run this project: https://pagure.io/fedora-commops/fedora-happiness-packets and it gives me errors even though I followed the instructions.
First I forked the repo, then cloned it to my computer and I followed the instructions listed in the setup section of the README.md file. When I run the command ./manage.py collectstatic I get this error:
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute
django.setup()
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models()
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/virtualenv/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/happinesspackets/messaging/models.py", line 15, in <module>
from happinesspackets.tasks import send_html_mail
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/happinesspackets/tasks.py", line 3, in <module>
from happinesspackets._celery import app
File "/Users/alexmarginean/Desktop/fed/fedora-happiness-packets/happinesspackets/_celery.py", line 2, in <module>
from celery import Celery
ImportError: No module named celery
I tried importing celery but that method didn't work and I don't want to mess with the project.
Looking at issue 49, it looks like celery is a dependency but it isn not listed in the requirements. Until that is fixed, you'll have to install it manually.
pip install celery
Have you done pip install -r requirements in the virtualenv ?
When I try to run python manage.py runserver I get this error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 363, in execute_from_command_line
utility.execute()
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/core/management/__init__.py", line 307, in execute
settings.INSTALLED_APPS
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Users/user/lokvi/lokvi_env/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/System/Library/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 have python 2.7 in my virtualenv. I noticed strange thing at the last lines of my stack trace, the line before the last line has path that goes like that: /lokvi_env/lib/python2.7 etc
But the last line goes like that System/Library/Frameworks etc, so it seems like path has changed from virtualenv to system. Is it ok?
You need to import settings module
from django.conf import settings
Oh, It was not the python path specific question, sorry. I just needed __init__.py in settings module inside of my project, since there were no settings it tried to find it in python lib itself and couldn't, I believe.
I am deploying new django new_app with the command django-admin.py startapp new_app, add it to installed apps in settings.py . Then after makemigrations and migrate commands everything is fine. Now I need to copy files from GitHub and replace default new_app folder with them.
I delete everything from new_app folder exept default migrations (is this right?) and delete migrations from the relevant cloned GitHub folder and copy everything else to new_app folder. So, the only thing left dafault is migrations.
After those actions makemirgations command responds with the following traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/django/django_project/denv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/django/django_project/denv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 312, in execute
django.setup()
File "/home/django/django_project/denv/local/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/django/django_project/denv/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/home/django/django_project/denv/local/lib/python2.7/site-packages/django/apps/config.py", line 86, in create
module = import_module(entry)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named `new_app`
I am trying to setup travis-ci for the first time with a django project of mine and I am getting this trace in the travis output...
0.17s$ python manage.py migrate
Traceback (most recent call last):
File "manage.py", line 13, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 316, in execute
settings.INSTALLED_APPS
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/python/2.7.9/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named py
The command "python manage.py migrate" exited with 1.
Now I can see that it is looking for a module named py instead of running the manage.py file but I don't see why that would happen, and I have found numerous resources online that have stated to run a command like that in the travi.yml file (heres one: https://gist.github.com/ndarville/3625246)
here is my travis.yml file:
script:
- python manage.py migrate
- python manage.py test
Now before I go running off and trying to get it to run by installing another module like tox or nose I would like to know if it is possible to do it this why and why it is failing and where to find the info in the docs... Thanks