[GH-ISSUE #1276] ImportError: No module named instance.settings after fresh install. #1032

Closed
opened 2026-02-27 11:14:50 +03:00 by kerem · 1 comment
Owner

Originally created by @prisma01 on GitHub (Oct 15, 2017).
Original GitHub issue: https://github.com/modoboa/modoboa/issues/1276

Hello,

i have some trouble installing modoboa.
OS: Debian 9 (stretch), python 2.7, apache/mod_wsgi
Installer: Only modoboa enbled, everything else I do manually.
Installer.cfg: https://pastebin.com/6EeVjg5Q
Output: https://pastebin.com/FWbWynVa
So Installer => everything is fine

sudo -u modoboa -i
source env/bin/activate

But when /srv/modoboa/instance/instance/wsgi.py is called by apache or I call it directly:
python ./instance/instance/wsgi.py
I get the ImportError:

Traceback (most recent call last):
File "./instance/instance/wsgi.py", line 16, in
application = get_wsgi_application()
File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/init.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/conf/init.py", line 53, in getattr
self._setup(name)
File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/conf/init.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/conf/init.py", line 97, in init
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/usr/lib/python2.7/importlib/init.py", line 37, in import_module
import(name)
ImportError: No module named instance.settings

I get the same error when installing modoboa manually and deploy instance with modoboa-admin.py...
Some Django pages state that it has something to do with paths or double paths (instance/instance), but all workarounds show no effect.

Originally created by @prisma01 on GitHub (Oct 15, 2017). Original GitHub issue: https://github.com/modoboa/modoboa/issues/1276 Hello, i have some trouble installing modoboa. OS: Debian 9 (stretch), python 2.7, apache/mod_wsgi Installer: Only modoboa enbled, everything else I do manually. Installer.cfg: [https://pastebin.com/6EeVjg5Q](https://pastebin.com/6EeVjg5Q) Output: [https://pastebin.com/FWbWynVa](https://pastebin.com/FWbWynVa) So Installer => everything is fine sudo -u modoboa -i source env/bin/activate But when /srv/modoboa/instance/instance/wsgi.py is called by apache or I call it directly: python ./instance/instance/wsgi.py I get the ImportError: > Traceback (most recent call last): > File "./instance/instance/wsgi.py", line 16, in <module> > application = get_wsgi_application() > File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application > django.setup(set_prefix=False) > File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/__init__.py", line 22, in setup > configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) > File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__ > self._setup(name) > File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup > self._wrapped = Settings(settings_module) > File "/srv/modoboa/env/local/lib/python2.7/site-packages/django/conf/__init__.py", line 97, in __init__ > mod = importlib.import_module(self.SETTINGS_MODULE) > File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module > __import__(name) > ImportError: No module named instance.settings I get the same error when installing modoboa manually and deploy instance with modoboa-admin.py... Some Django pages state that it has something to do with paths or double paths (instance/instance), but all workarounds show no effect.
kerem closed this issue 2026-02-27 11:14:50 +03:00
Author
Owner

@prisma01 commented on GitHub (Oct 17, 2017):

Hi, I found out more details.
the missing instance.settings is happening due to a missing path to the instance. There are two possible solutions:
a) use the daemon mode of modwsgi as discribed in the documentation Manual Install -> Webserver.
b) beef up wsgi.py a little

I had to choose b) as the daemons keep on crashing and i only got timeouts from clients.
This is how my wsgi.py looks like:

import os
import sys

#Add instance path
sys.path.append('/srv/modoboa/instance')

#Use virtualenv in non daemon mode wsgi
activate_this = '/srv/modoboa/env/bin/activate_this.py'
execfile(activate_this, dict(file=activate_this))

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "instance.settings")

application = get_wsgi_application()

What also helped against bad Request (400) errors was to modify the ALLOWED_HOSTS in the settings.py:

ALLOWED_HOSTS = [
'.example.com', # Allow domain and subdomains
'.example.com.', # Also allow FQDN and subdomains
]

<!-- gh-comment-id:337185844 --> @prisma01 commented on GitHub (Oct 17, 2017): Hi, I found out more details. the missing instance.settings is happening due to a missing path to the instance. There are two possible solutions: a) use the daemon mode of modwsgi as discribed in the documentation Manual Install -> Webserver. b) beef up wsgi.py a little I had to choose b) as the daemons keep on crashing and i only got timeouts from clients. This is how my wsgi.py looks like: > import os > import sys > > #Add instance path > sys.path.append('/srv/modoboa/instance') > > #Use virtualenv in non daemon mode wsgi > activate_this = '/srv/modoboa/env/bin/activate_this.py' > execfile(activate_this, dict(__file__=activate_this)) > > from django.core.wsgi import get_wsgi_application > > os.environ.setdefault("DJANGO_SETTINGS_MODULE", "instance.settings") > > application = get_wsgi_application() What also helped against bad Request (400) errors was to modify the ALLOWED_HOSTS in the settings.py: > ALLOWED_HOSTS = [ > '.example.com', # Allow domain and subdomains > '.example.com.', # Also allow FQDN and subdomains > ]
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/modoboa-modoboa#1032
No description provided.