I got the above error while using bitnami django. All settings done according doc: https://docs.bitnami.com/virtual-machine/components/django/#production python version: Python 3.6.4 :: Anaconda, Inc. django version: 2.0.2-3
wsgi.py:
import os,sys
sys.path.append('/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject')
os.environ.setdefault("PYTHON_EGG_CACHE", "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/egg_cache")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "MyProject.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
httpd-app.conf:
<IfDefine !IS_DJANGOSTACK_LOADED>
Define IS_DJANGOSTACK_LOADED
WSGIDaemonProcess wsgi-djangostack processes=2 threads=15 display-name=%{GROUP}
</IfDefine>
<Directory "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject">
Options +MultiViews
AllowOverride All
<IfVersion < 2.3 >
Order allow,deny
Allow from all
</IfVersion>
<IfVersion >= 2.3>
Require all granted
</IfVersion>
WSGIProcessGroup wsgi-djangostack
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
Alias /MyProject/static "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/contrib/admin/static"
WSGIScriptAlias /MyProject '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'
httpd-prefix.conf:
# Include file
Include "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/conf/httpd-app.conf"
corresponding url added to /Applications/djangostack-2.0.2-3/apache2/conf/bitnami/bitnami-apps-prefix.conf file
But when I'm trying to access app via browser I've got error in log:
[Fri Jun 22 16:37:20.873873 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Target WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py' cannot be loaded as Python module.
[Fri Jun 22 16:37:20.874027 2018] [wsgi:error] [pid 29099] [remote ::1:62098] mod_wsgi (pid=29099): Exception occurred processing WSGI script '/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py'.
[Fri Jun 22 16:37:20.875482 2018] [wsgi:error] [pid 29099] [remote ::1:62098] Traceback (most recent call last):
[Fri Jun 22 16:37:20.875554 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject/wsgi.py", line 17, in <module>
[Fri Jun 22 16:37:20.875568 2018] [wsgi:error] [pid 29099] [remote ::1:62098] application = get_wsgi_application()
[Fri Jun 22 16:37:20.875584 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/core/wsgi.py", line 12, in get_wsgi_application
[Fri Jun 22 16:37:20.875594 2018] [wsgi:error] [pid 29099] [remote ::1:62098] django.setup(set_prefix=False)
[Fri Jun 22 16:37:20.875608 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/__init__.py", line 24, in setup
[Fri Jun 22 16:37:20.875618 2018] [wsgi:error] [pid 29099] [remote ::1:62098] apps.populate(settings.INSTALLED_APPS)
[Fri Jun 22 16:37:20.875631 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/registry.py", line 89, in populate
[Fri Jun 22 16:37:20.875641 2018] [wsgi:error] [pid 29099] [remote ::1:62098] app_config = AppConfig.create(entry)
[Fri Jun 22 16:37:20.875654 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/apps/django/lib/python3.6/site-packages/Django-2.0.2-py3.6.egg/django/apps/config.py", line 90, in create
[Fri Jun 22 16:37:20.875664 2018] [wsgi:error] [pid 29099] [remote ::1:62098] module = import_module(entry)
[Fri Jun 22 16:37:20.875677 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "/Applications/djangostack-2.0.2-3/python/lib/python3.6/importlib/__init__.py", line 126, in import_module
[Fri Jun 22 16:37:20.875687 2018] [wsgi:error] [pid 29099] [remote ::1:62098] return _bootstrap._gcd_import(name[level:], package, level)
[Fri Jun 22 16:37:20.875700 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 994, in _gcd_import
[Fri Jun 22 16:37:20.875728 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 971, in _find_and_load
[Fri Jun 22 16:37:20.875736 2018] [wsgi:error] [pid 29099] [remote ::1:62098] File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
[Fri Jun 22 16:37:20.875752 2018] [wsgi:error] [pid 29099] [remote ::1:62098] ModuleNotFoundError: No module named 'widget_tweaks'
I have installed widget_tweaks using:
pip3 install django-widget-tweaks
But when I stop Apache and run app using command
python3 manage.py runserver localhost:8080
the app works perfectly fine.
My urls.py under /Applications/djangostack-2.0.2-3/apps/django/django_projects/MyProject/MyProject look like:
from django.contrib import admin
from django.urls import path, include,re_path
urlpatterns = [
path('', include('APP.urls')),
re_path(r'^admin/', admin.site.urls, name='admin'),
]
So I assume error within Apache configuration. Any help or advises will be appreciated!
Thank you Jota for providing one of the solution.
Solution 1: For Mac OS, when I execute /Applications/djangostack-2.0.2-3/use_djangostack, I enter Bitnami console. I just had to install all the necessary modules and custom project ran successfully using apache.
Solution 2: In case you don't wanna use bitnami console,
1) Install mod_wsgi using pip, preferably into a Python virtual environment. Ensure pip is for the version of Python you want to use.
pip install mod_wsgi
2) Display the config to add to Apache configuration file to load this mod_wsgi by running:
mod_wsgi-express module-config
3) Take the output of above command to display config and add to Apache configuration. (httpd.conf file)
4) restart the apache using ctlscript.sh file. In my case the command looked like:
/Applications/djangostack-2.0.2-3/ctlscript.sh restart apache
5) After restarting, my custom project ran successfully.
Regards,
Amey Kelekar