When deploying a Django (v3.0.3) project to AWS Lambda using Zappa, I get an error that the package django.contrib.staticfiles could not be found.
This looks strange as this package is part of the Django core apps and the project runs on the local development server with no issues whatsoever. My app listing looks as follows:
INSTALLED_APPS = [
# Django apps
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
# 3rd party apps
'rest_framework',
'rest_framework.authtoken',
'django_extensions',
'mapwidgets',
'crispy_forms',
'attachments',
'leaflet',
'django_tables2',
'django_filters',
'zappa_django_utils',
'django_s3_storage',
# Project apps
'myapp.apps.MyappConfig'
]
Cloudwatch gives me the following error log. Have been trying various solutions (reinstalling environment, redeploying Lambda function, ...). Nothing works and this is slowly driving me nuts ;-). The Lambda function managed to run before and I have no idea what I changed to break it. I can confirm that the necessary permissions to access static files in the designated S3 bucket are available and working. Any ideas on what's happening from the community?
[ERROR] ModuleNotFoundError: No module named 'django.contrib.staticfiles'
Traceback (most recent call last):
File "/var/task/handler.py", line 609, in lambda_handler
return LambdaHandler.lambda_handler(event, context)
File "/var/task/handler.py", line 240, in lambda_handler
handler = cls()
File "/var/task/handler.py", line 146, in __init__
wsgi_app_function = get_django_wsgi(self.settings.DJANGO_SETTINGS)
File "/var/task/zappa/ext/django_zappa.py", line 20, in get_django_wsgi
return get_wsgi_application()
File "/var/task/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/var/task/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/var/task/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/var/task/django/apps/config.py", line 136, in create
import_module(entry)
File "/var/lang/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
Related
I want to update my heroku site with this command heroku run python manage.py migrate, but the error appeared:
» Warning: heroku update available from 7.53.0 to 7.60.2.
Running python manage.py migrate on ⬢ mighty-harbor-18334... up, run.5980 (Free)
Traceback (most recent call last):
File "/app/manage.py", line 22, in <module>
main()
File "/app/manage.py", line 18, in main
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 425, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/__init__.py", line 401, in execute
django.setup()
File "/app/.heroku/python/lib/python3.10/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/registry.py", line 91, in populate
app_config = AppConfig.create(entry)
File "/app/.heroku/python/lib/python3.10/site-packages/django/apps/config.py", line 223, in create
import_module(entry)
File "/app/.heroku/python/lib/python3.10/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django_apscheduler'
I installed django_apscheduler with pip install django_apscheduler for sure. My python version is 3.10.2, and in my settings.py, the app module is in INSTALLED_APPS such:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'myapp'
'django_apscheduler',
]
I am not sure why the ModuleNotFoundError would occured, any help will be appreciated.
You forgot after 'myapp' put a comma in INSTALLED_APPS
I am trying to create a Django python API, and when I created the first app 'authentication' with 'python manage.py startapp authentication', I got the following error while running the server:
Mylaptop#DESKT0P-101D6PT MINGW64 -/Desktop/pizza_delivery S python ./pizza/manage.py runserver Watching for file changes with StatReloader Exception in thread django-main-thread:
Traceback (most recent call last):
File "C:\Program Files\Python39\lib\threading.py”, line 973, in _bootstrap_inn er
self. run()
File "C:\Program Files\Python39\lib\threading.py”, line 910, in run self._target(*self._args, **self._kwargs)
File ”C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\ut ils\autoreload.py”, line 64, in wrapper fn(*args, **kwargs)
File ”C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\co re\management\commands\runserver.py", line 125, in inner_run autoreload.raise_last_exception()
File "C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\ut ils\autoreload.py", line 87, in raise_last_exception raise _exception[l]
File "C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\co
re\management\ init .py", line 398, in execute
autoreload.check_errors(django.setup)()
File "C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\ut ils\autoreload.py", line 64, in wrapper fn(*args, **kwargs)
File "C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\
init .py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\ap ps\registry.py", line 91, in populate app_config = AppConfig.create(entry)
File "C:\Users\Mylaptop\Desktop\pizza_delivery\env\lib\site-packages\django\ap ps\config.py", line 213, in create mod = import_module(mod_path)
File "C:\Program Files\Python39\lib\importlib\ init .py", line 127, in impor
t_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'authentication.apps'
I did add the app name to the 'setting.py' file :
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authentication.apps.AuthenticationConfig',
'orders.apps.OrdersConfig',]
I am pretty sure that I need to specify the path, but I don't know how !!!
Note that my folder is organized as follows, and the main project is named 'pizza':
folder content
Can anyone help me please ???
There is no need.
'authentication.apps.AuthenticationConfig',
'orders.apps.OrdersConfig'
just add app_name
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'authentication',
'orders',]
And Why you use python manage.py startapp authentication this code again. You already have authentication app in your folder.
well, to solve the problem I changed the location of the authentication folder :
I put it in the project folder.
So I'm trying to put up a demo of a django project on Heroku that runs fine locally and loads when I uninstall the package Pyo, but it throws an OSerror when I reinstall it (OSError at /
Exception Value: /app/.pyo/3.6_64/libs/libasound-fb332ab3.so.2.0.0: cannot open shared object -- see below for full traceback). I've added a buildpack that installs the libasound and recommened packages, but I still get the error. What am I missing? I see the Linux wheel fix symlink (https://github.com/belangeo/pyo/blob/master/pyo/_linux_wheel_fix_symlinks.py). Is the issue here? Any help greatly appreciated.
Error:
Request Method: GET
Request URL: ---
Django Version: 3.0.3
Python Version: 3.6.10
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'core',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'allauth.socialaccount.providers.google']
Installed Middleware:
('whitenoise.middleware.WhiteNoiseMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/app/.heroku/python/lib/python3.6/site-packages/django/core/handlers/base.py", line 100, in _get_response
resolver_match = resolver.resolve(request.path_info)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 544, in resolve
for pattern in self.url_patterns:
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 588, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/app/.heroku/python/lib/python3.6/site-packages/django/utils/functional.py", line 48, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/app/.heroku/python/lib/python3.6/site-packages/django/urls/resolvers.py", line 581, in urlconf_module
return import_module(self.urlconf_name)
File "/app/.heroku/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
<source code not available>
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
<source code not available>
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
<source code not available>
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
<source code not available>
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
<source code not available>
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
<source code not available>
File "/app/autosubclub/urls.py", line 20, in <module>
from core import views
File "/app/core/views.py", line 8, in <module>
from pyo import PVMix, PVMorph, PVAnal, SfPlayer, Vocoder, Server, Record, sndinfo
File "/app/.heroku/python/lib/python3.6/site-packages/pyo/__init__.py", line 25, in <module>
from . import _linux_wheel_fix_symlinks
File "/app/.heroku/python/lib/python3.6/site-packages/pyo/_linux_wheel_fix_symlinks.py", line 88, in <module>
libasound = ctypes.CDLL(libasound, mode=ctypes.RTLD_GLOBAL)
File "/app/.heroku/python/lib/python3.6/ctypes/__init__.py", line 348, in __init__
self._handle = _dlopen(self._name, mode)
Exception Type: OSError at /
Exception Value: /app/.pyo/3.6_64/libs/libasound-fb332ab3.so.2.0.0: cannot open shared object file: No such file or directory
I just want to leave this for anyone else who experiences this issue in the future. Pyo will not work on a hobby dev Heroku DYNO due to the symlink wheels created that attempt to reach out of the ./app folder for ibasound-fb332ab3.so.2.0.0 and libjack-07a61c7b.so.0.1.0, but Heroku apps can't reach out of that directory because it's where everything is stored.
You can install on other cloud environments like Digital Ocean & Amazon EC2 where you can install Ubuntu on the server and have full access. I chose Digital Ocean for a while, but ended up just teaching the client how to run the web app locally and writing code to push the generated files to Amazon s3.
I am currently making a django application that requires me to add Bower and django-schedule library. When i try to make migrations, I get this error:
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line 347, in execute
django.setup()
File "C:\Python34\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "C:\Python34\lib\site-packages\django\apps\registry.py", line 89, in populate
app_config = AppConfig.create(entry)
File "C:\Python34\lib\site-packages\django\apps\config.py", line 90, in create
module = import_module(entry)
File "C:\Python34\lib\importlib\__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'djangobower'
my settings.py consists of:
INSTALLED_APPS = [
'patients.apps.PatientsConfig',
'accounts.apps.AccountsConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'djangobower',
'schedule',
]
BOWER_COMPONENTS_ROOT = 'Project root/components/'
BOWER_INSTALLED_APPS = (
'jquery',
'jquery-ui',
'bootstrap',
'fullcalendar'
)
i am using pycharm as my IDE and in bower apps, it shows jquery-ui and fullcalendar as unresolved, even though I have installed them. Any help is appreciated.
It seems like bower isnt really installed check that by pip list.
If it is so did you do ./manage.py bower install ?
I think you should have the PROJECT_ROOT variable set somewhere in your settings.py file.
BOWER_COMPONENTS_ROOT = 'Project root/components/'
should be something like
BOWER_COMPONENTS_ROOT = os.path.join(PROJECT_ROOT, 'components')
In my case the variable in the latest Django install was BASE_DIR
I am trying to upgrade my Django project to Django 2.0, currently the version is 1.8.19. I figured I would do it step by step, firstly upgrading to 1.9, then 1.10 and so on till 2.0. The problem is that I get error message
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/core/management/__init__.py", line 302, in execute
settings.INSTALLED_APPS
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/conf/__init__.py", line 55, in __getattr__
self._setup(name)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/conf/__init__.py", line 43, in _setup
self._wrapped = Settings(settings_module)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/conf/__init__.py", line 99, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/riddle/tmp1/example-project/app/ad_akumuliatoriai_lt/settings.py", line 140, in <module>
from apps.frontend.ad_akumuliatoriai.models import Language
File "/home/riddle/tmp1/example-project/app/apps/frontend/ad_akumuliatoriai/models.py", line 5, in <module>
from ordered_model.models import OrderedModel
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/ordered_model/models.py", line 20, in <module>
class OrderedModelBase(models.Model):
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/db/models/base.py", line 94, in __new__
app_config = apps.get_containing_app_config(module)
File "/home/riddle/tmp1/example-project/env/lib/python3.6/site-packages/django/apps/registry.py", line 239, in get_containing_app_config
self.check_apps_ready()
File "/home/riddle/tmp1/example-project/env/lib/python3.6/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 have read the thread: Django upgrading to 1.9 error "AppRegistryNotReady: Apps aren't loaded yet."
I have tried using
import django
django.setup()
at the top of my settings.py file with no luck.
I've made an assumption that the problem is with the third party apps.
My main question is, how to start checking for invalid third party apps, since commenting them out one by one does not remove the error. I've checked every app's that I've installed via pip documentation, and added the required lines
to the INSTALLED_APPS in settings.py. It seems that some packages, such as django-jquery, django-libsass, django-ordered-model have not been developed for some years, however, according to django==1.9 release date, those apps should have worked on django==1.9 (or maybe that is the mistake of my thinking?).
I am ready to post more information from my project if needed.
My settings.py fragment:
INSTALLED_APPS = (
'hvad',
'compressor',
'filebrowser',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'jquery',
'tinymce',
'apps.frontend.ad_akumuliatoriai',
'ordered_model',
'geoposition',
)
The output of "pip freeze":
Django==1.9
django-appconf==1.0.2
django-compressor==2.2
django-filebrowser-no-grappelli==3.7.4
django-geoposition==0.3.0
django-hvad==1.8.0
django-jquery==3.1.0
django-libsass==0.7
django-ordered-model==1.4.3
django-tinymce==2.7.0
libsass==0.14.2
Pillow==5.1.0
psycopg2==2.7.4
pytz==2018.3
rcssmin==1.0.6
rjsmin==1.0.12
six==1.11.0
The traceback suggests you are importing a model in your settings.py:
from apps.frontend.ad_akumuliatoriai.models import Language
You shouldn't do this. Remove the import.