I've installed django on OS X 10.9.5 using pip, and everything worked great for a day. I fired it up the next day and the tool seems to be broken.
Now, any command I issue aside from "startproject" fails with the following output. I've tried starting a totally clean project, and I get the same thing.
$ django-admin manage.py check
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 11, in <module>
sys.exit(execute_from_command_line())
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 182, in fetch_command
settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/__init__.py", line 42, in _setup
% (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Not sure how helpful it is, since this is a fresh project, but here's the output from manage.py:
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testdjango.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
I've tried uninstall/reinstalling django. Where should I look next?
Your syntax is incorrect. You should either type
django-admin check
or
python manage.py check
That being said; django-admin is only useful when creating the project. You should use the manage.py script for project-specific tasks. From the docs:
Generally, when working on a single Django project, it’s easier to use manage.py than django-admin. If you need to switch between multiple Django settings files, use django-admin with DJANGO_SETTINGS_MODULE or the --settings command line option.
Related
I am trying to host a website using django and I installed fontawesome-free[version=5.15.3] which I used in my project but when I am trying to run python manage.py makemigrations I am getting this error ImproperlyConfigured: The app label 'fontawesome-free' is not a valid Python identifier. How do I fix this problem?
Full traceback:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
main()
File "manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/home/guitarwebsite/.virtualenvs/my-virtualenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/home/guitarwebsite/.virtualenvs/my-virtualenv/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
django.setup()
File "/home/guitarwebsite/.virtualenvs/my-virtualenv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/guitarwebsite/.virtualenvs/my-virtualenv/lib/python3.8/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/home/guitarwebsite/.virtualenvs/my-virtualenv/lib/python3.8/site-packages/django/apps/config.py", line 255, in create
return app_config_class(app_name, app_module)
File "/home/guitarwebsite/.virtualenvs/my-virtualenv/lib/python3.8/site-packages/django/apps/config.py", line 38, in __init__
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: The app label 'fontawesome-free' is not a valid Python identifier.
As #AKX said, this is a known issue for fontawesome-free, fontawesome-pro + django >= 3.2.
This quick-fix helped.
Just before the INSTALLED_APPS add this
import sys
sys.modules['fontawesome_free'] = __import__('fontawesome-free')
or
sys.modules['fontawesome_pro'] = __import__('fontawesome-pro')
and then add "fontawesome_free" or "fontawesome_pro" to your INSTALLED_APPS
INSTALLED_APPS = [
.........
"fontawesome_free",
#or
"fontawesome_pro",
.........
]
Semi fixed as of May 21st. It's fixed with renaming the package to fontawesomefree. Here is the github issue for more info
This is a known issue in the fontawesome-free Python package, rendering it unusable as a Django app for the time being: https://github.com/FortAwesome/Font-Awesome/issues/17801
Thanks in Advance for My Query.
I have created a django project which has manage.py file inside src folder it works fine when running terminal from SRC folder.
FOr Heroku deployement manage.py should be placed in root directory so i updated manage.py file with "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.tweetme.settings")"
Changed "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tweetme.settings")" to "os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.tweetme.settings")" import issue is faced on running locally. Need solution how to import setting.py inside two folder deep.
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "src.tweetme.settings")
try:
from django.core.management import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
try:
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise
execute_from_command_line(sys.argv)
I am facing following Error: attached Error_Message.png
Hiras-Mac-mini-2:tweethere apple$ python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 23, in
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/django/core/management/init.py", line 363, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/init.py", line 307, in execute
settings.INSTALLED_APPS
File "/Library/Python/2.7/site-packages/django/conf/init.py", line 56, in getattr
self._setup(name)
File "/Library/Python/2.7/site-packages/django/conf/init.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/Library/Python/2.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 src.tweetme.settings
***This Is my Package Structure:***attached Project_Structure.png
-Project
-bin
-include
-lib
-src
-subProject1
-subProject2
-subProject3
-mainProject
-Settings
-__init__.py
-base.py
-local.py
-production.py
-manage.py
-db.sqlite3
-static-serve
-.env
-.python
-manage.py
-ProcFile
-requirements.txt
Project_Structure.pngError_Message.png
If manage.py is not in the src directory, then you need to add src to the Python path.
import sys
sys.path.append('src')
You should then keep DJANGO_SETTINGS_MODULE as it was, without src.
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tweetme.settings")
I'm writing some unit tests for an existing django project that has had no unit tests to date.
When I run the tests from the command line using
./manage.py test
I get
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 341, in execute
django.setup()
File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 90, in create
module = import_module(entry)
File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named hijack
Now hijack is actually installed as I can use it from the browser when I run the server using
./manage.py runserver
The contents of manage.py is
#!/usr/bin/env python
import os
import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mtmdjango.settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
So ... how I can disable the reference for hijack when running tests or how can I enable hijack to be available under the command line when running tests?
(can someone create and add the tag django-hijack)
I worked through the tutorials at
https://docs.djangoproject.com/en/1.10/intro/tutorial01/ through https://docs.djangoproject.com/en/1.10/intro/tutorial05/
It turned out my command line was wrong.
python manage.py test contacts
gives me the output I was expecting.
Can anyone see what I'm doing wrong here? No matter what I try, I can't seem to set it to correctly detect the settings for Django. Works fine when being run manually in terminal in the active virtualenv.
Supervisor
[program:celery_beetlejuice]
command = /home/padraic/.virtualenvs/beetlejuice/bin/python /home/padraic/CodeDev/beetlejuice/beetlejuice_django/manage.py celeryd -B -E -l INFO
directory=/home/padraic/CodeDev/beetlejuice/beetlejuice_django
environment=PYTHONPATH="/home/padraic/CodeDev/beetlejuice/beetlejuice_django", DJANGO_SETTINGS_MODULE="beetlejuice_django.settings"
user = padraic
autostart=true
autorestart=true
stdout_logfile=/home/padraic/CodeDev/beetlejuice/beetlejuice_django/logs/celeryd.log
stderr_logfile=/home/padraic/CodeDev/beetlejuice/beetlejuice_django/logs/celeryd.log
redirect_stderr=true
priority=998
numprocs=1
Traceback
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/home/padraic/.virtualenvs/beetlejuice/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/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 263, in fetch_command
app_name = get_commands()[subcommand]
File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 109, in get_commands
apps = settings.INSTALLED_APPS
File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
self._setup(name)
File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in _setup
self._wrapped = Settings(settings_module)
File "/home/padraic/.virtualenvs/beetlejuice/local/lib/python2.7/site-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 'beetlejuice_django.settings' (Is it on sys.path?):
Sigh... figured out the error...
So! I have my settings.py file which contains:
[settings.py]
import os
BEETLEJUICE_STATE = os.environ.get('BTJC_STATE', None)
if BEETLEJUICE_STATE == 'LOCAL':
from local_settings import *
elif BEETLEJUICE_STATE == 'DEV':
from development_settings import *
elif BEETLEJUICE_STATE == 'PROD':
from production_settings import *
else:
raise ImportError
<aside>
... which used to be the right way to do things (or so I was told). I'm planning to switch over to the way that Audrey and Danny recommend in Two Scoops of Django, the gist of which being:
settings/
__init__.py
base.py
local.py
test.py
production.py
... and explicitly call my settings files from now on, e.g.
python manage.py runserver --settings='settings.production'
...which imports from base.py and has all the production-specific settings.
</aside>
... and I had BTJC_STATE being exported in the virtualenvwrapper postactivate file, except that by running celeryd via supervisor I wasn't activating anything and thereby skipping that file entirely! This raised the ImportError but I didn't realise that was where it was coming from =(
Adding a string explaining the exception is a good idea... and apparently using ImproperlyConfigured is a better way to raise for this issue. So by changing the one line below in my .conf file, it started working perfectly.
[program:celery_beetlejuice]
<snip>
environment=BTJC_STATE='LOCAL'
<snip>
So that works now and I'm happy, but I need to find a good way of setting environment variables (like database passwords, api keys, and such) that will work well with for inside a non-activated in-use virtualenv.
All advice welcome on that, message me and I'll update this with the solution =)
I'm trying to setup a local django installation, but am facing a lot of problems in configuring it properly.
Trying to start the server doesn't work:
admins-macbook:myproject Admin$ python manage.py runserver 8080
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/Admin/myapp/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 "/Users/Admin/myapp/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/Admin/myapp/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 "/Users/Admin/myapp/lib/python2.7/site-packages/django/core/servers/basehttp.py", line 26, in <module>
from django.views import static
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/views/static.py", line 95, in <module>
template_translatable = ugettext_noop(u"Index of %(directory)s")
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 75, in gettext_noop
return _trans.gettext_noop(message)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 48, in __getattr__
if settings.USE_I18N:
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/utils/functional.py", line 184, in inner
self._setup()
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
self._wrapped = Settings(settings_module)
File "/Users/Admin/myapp/lib/python2.7/site-packages/django/conf/__init__.py", line 95, in __init__
raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
ImportError: Could not import settings '{{ project_name }}.settings' (Is it on sys.path?): No module named {{ project_name }}.settings
I have mainly been following the directions here.
I am completely lost about what I may be doing wrong. I googled and found some people saying that either this could be because of naming conflicts between the project name or trying to use two installations simultaneously. I changed the name of my project, and checked to see that I only have one django installation, but still am facing the same problem. Can anyone help? Thanks for any ideas!
EDIT: Checking the paths
admins-macbook:Downloads Admin$ echo $PATH
/Users/Admin/myapp/lib/python2.7/site-packages/django/conf/myproject:/Users/Admin/myapp/lib/python2.7/site-packages/django/conf:/Users/Admin/myapp/lib/python2.7/site-packages/django:/Users/Admin/myapp/lib/python2.7/site-packages:/Users/Admin/myapp/lib/python2.7:/Users/Admin/myapp/lib:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
EDIT: Adding the directory structure (did not change, straight from django 1.4.2):
-bin
-contrib
-core
-(etc.)
-django
--conf
---__init__
---app_template
---urls
---myproject
----myapp
-----settings.py
-----urls.py
-----(etc.)
----manage.py
When manage.py is first created it includes a code that adds the path to the project's settings.py to the python path whenever a command (such as run server) is run. Since you changed the names of the folders, manage.py can't find the settings anymore.
Open up manage.py and change the old project name there to the new one. There are other places where this problem might show up so keep an eye for references to your old project's name that would cause trouble