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.
Related
The collect static runs fine when it is executed manually from the command line, but it fails with sentry's built-in git function
But I know this is not sentry problem, because the problem occurs when I use gitpython to retrieve the git path
source /home/ubuntu/.virtualenvs/myproject/bin/activate && python /home/ubuntu/myproject/manage.py collectstatic -v 1 --noinput
Traceback (most recent call last):
File "/home/ubuntu/myproject/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
utility.execute()
File "/home/ubuntu/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "/home/ubuntu/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/home/ubuntu/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/home/ubuntu/.virtualenvs/myproject/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/ubuntu/myproject/myproject/settings/prod.py", line 100, in <module>
"release": raven.fetch_git_sha(os.path.dirname(os.pardir)),
File "/home/ubuntu/.virtualenvs/myproject/local/lib/python2.7/site-packages/raven/versioning.py", line 25, in fetch_git_sha
'Cannot identify HEAD for git repository at %s' % (path,))
raven.exceptions.InvalidGitRepository: Cannot identify HEAD for git repository at
Here is another example where fabric would fail while the local execution will be okay:
from git import Repo
from . import appname
import os
print appname.__path__
base_dir = os.path.dirname(appname.__path__[0])
repo = Repo(base_dir)
dt = repo.head.commit.committed_date
the appname's path will be empty. I am using from fabric.context_managers import cd for all my fabric tasks.
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
I'm writing this post because after hours of research around, no real solution was found about my issue.
I've a Django project that used to run on another computer. Now, I've a new one, I've reinstalled Django and VirtualEnvWrapper.
I've cloned my project from my git and I can work and deploy without any issues.
Running ./manage.py works when I'm on the correct virtualenv (via workon 'my_project_name').
My problem is that I can't generate translations any more.
Here is the trace-back:
(MyProject)--- python/MyProject ‹master*➔ M› »django-admin.py makemessages --all
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 376, in execute
sys.stdout.write(self.main_help_text() + '\n')
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 240, in main_help_text
for name, app in six.iteritems(get_commands()):
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 107, in get_commands
apps = settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 54, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 49, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 132, in __init__
% (self.SETTINGS_MODULE, e)
ImportError: Could not import settings 'MyProject.settings.local' (Is it on sys.path? Is there an import error in the settings file?): No module named MyProject.settings.local
When I'm checking my sys.path, here is the content:
/Users/jbcollet/.virtualenvs/MyProject/lib/python27.zip
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/plat-darwin
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/plat-mac
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/plat-mac/lib-scriptpackages
/Users/jbcollet/.virtualenvs/MyProject/Extras/lib/python
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/lib-tk
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/lib-old
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/lib-dynload
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages
/Users/jbcollet/.virtualenvs/MyProject/lib/python2.7/site-packages
Can someone help me with this?
Thanks a lot
Im on installing edX platform using this instructions ( http://nkokkos.wordpress.com/2013/10/09/setting-up-edx-platform-on-ubutnu/ ),
I followed; every step successfully, but on ./manage.py lms syncdb –migrate, I face to this error:
Traceback (most recent call last):
File "manage.py", line 90, in <module>
startup = importlib.import_module(edx_args.startup)
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/peyman/dev/edx/lms/startup.py", line 9, in <module>
settings.INSTALLED_APPS # pylint: disable=W0104
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 134, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings 'lms.envs.dev' (Is it on sys.path?): No module named xblock.fields
How can I fix it?
For anyone landing here for trouble with Open edX installation, try this latest guide instead of the one linked above:
http://edx.readthedocs.io/projects/edx-installing-configuring-and-running/en/latest/
i checked the code accordingly in your edx-platform folder structure, look for lms\envs\ there many environment file for migration exists
I need to ask because I'm starting in Django and it was impossible for me to continue with the tutorial that I'm following. I've just completed a Python course, I know the basics of python. The case is that I've installed Django in my mac and it's OK because when I do in the IDLE the
import django
print django.VERSION
It makes a good answer without errors in IDLE (is the software that I use to write python code). But when I execute in the Terminal the command:
python manage.py runserver
It raises this error:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/django-admin.py", line 5, in <module>
management.execute_from_command_line()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/__init__.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 8, in <module>
from django.core.servers.basehttp import AdminMediaHandler, run, WSGIServerException, get_internal_wsgi_application
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/django/conf/__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
I also want to ask you some questions:
Can I use XAMPP instead of Django? How?
What is Django used for exactly?
I've installed PyDev in Eclipse. How can I set Django to execute code properly?
call command django-admin startproject xxx under the target directory. You can get three .py files: setting.py, urls.py and manage.py. And you can execute python manage.py runserver command
I think it's slightly outdated now, but I'd seriously recommend going through the Djangobook examples. It'll explain how to set up Django properly, and give a pretty good foundation in how to use it.