No module named 'new_app' Django 1.8 error - python

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`

Related

Can't run a specific django project in a virtualenv

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 ?

Django: no module named settings

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.

ImportError: No module named books.apps (Django)

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.

travic-ci build failing with django project

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

Every time I run Python manage.py I get this error

pycharm#glenn-liveconsole3:~/mysite/quickstart$ django-admin.py syncdb
Traceback (most recent call last):
File "/home/pycharm/.virtualenvs/anchondo/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command
_line
utility.execute()
File "/home/pycharm/.virtualenvs/anchondo/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/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/core/management/sql.py", line 9, in <module>
from django.db import models
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/db/__init__.py", line 11, in <module>
if settings.DATABASES and DEFAULT_DB_ALIAS not in settings.DATABASES:
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/pycharm/.virtualenvs/anchondo/local/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES, but settings are not configured. You must either define the environment va
riable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
All I am doing is running python manage.py syncdb or python manage.py migrate I am trying to update the website the models created a new model an am trying to migrate the info website works but I can not do syncdb in the console
When you create your project with django-admin startproject a manage.py will be generated that has a line like:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")
where my_project is your project name. This points to your settings file. Make sure the line exists and point to the right settings module.
Also use manage.py instead of django-admin to manage an existing project.

Categories

Resources