ModuleNotFoundError: No module named 'macelleria_progetto.settings'

I’m trying to deploy a django on Linux server (AWS Lightsail Bitnami ) .

I’ve loaded the data and set the conf file in apache (using mod-wsgi).
But don’t work.
In the server_error (logs) the error is:

[wsgi:error] [pid 16260] [remote 79.52.250.157:63175]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[wsgi:error] [pid 16260] [remote 79.52.250.157:63175]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[wsgi:error] [pid 16260] [remote 79.52.250.157:63175]   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[wsgi:error] [pid 16260] [remote 79.52.250.157:63175] ModuleNotFoundError: No module named 'macelleria_progetto.settings'
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497] mod_wsgi (pid=16259): Failed to exec Python script file '/opt/bitnami/projects/macelleria_sito1/macelleria_progetto/macelleria_progetto/wsgi.py'.
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497] mod_wsgi (pid=16259): Exception occurred processing WSGI script '/opt/bitnami/projects/macelleria_sito1/macelleria_progetto/macelleria_progetto/wsgi.py'.
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497] Traceback (most recent call last):
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/projects/macelleria_sito1/macelleria_progetto/macelleria_progetto/wsgi.py", line 13, in <module>
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     application = get_wsgi_application()
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/apache/htdocs/projects/macelleria_env/lib/python3.8/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     django.setup(set_prefix=False)
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/apache/htdocs/projects/macelleria_env/lib/python3.8/site-packages/django/__init__.py", line 19, in setup
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/apache/htdocs/projects/macelleria_env/lib/python3.8/site-packages/django/conf/__init__.py", line 82, in __getattr__
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     self._setup(name)
[pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/apache/htdocs/projects/macelleria_env/lib/python3.8/site-packages/django/conf/__init__.py", line 69, in _setup
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     self._wrapped = Settings(settings_module)
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/apache/htdocs/projects/macelleria_env/lib/python3.8/site-packages/django/conf/__init__.py", line 170, in __init__
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     mod = importlib.import_module(self.SETTINGS_MODULE)
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "/opt/bitnami/python/lib/python3.8/importlib/__init__.py", line 127, in import_module
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]     return _bootstrap._gcd_import(name[level:], package, level)
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497]   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
[wsgi:error] [pid 16259] [remote 79.52.250.157:63497] ModuleNotFoundError: No module named 'macelleria_progetto.settings'

How I can resolve this ? I have to edit ‘wsgi.py’ file ?

‘macelleria_progetto’ IS THE NAME OF PROJECT, NOT AN APP !

p.s: here my v-vhost file in apache :

<IfDefine !IS_macelleria_sito1_LOADED>

Define IS_macelleria_sito1_LOADED

WSGIDaemonProcess macelleria_sito1 python-home=/opt/bitnami/apache/htdocs/projects/macelleria_env python-path=/opt/bitnami/projects/macelleria_sito1 processes=2 threads$

</IfDefine>

<VirtualHost *:443 _default_:443>

ServerAlias *

SSLEngine on

SSLCertificateFile "/etc/letsencrypt/aa/aa/aa"

SSLCertificateKeyFile "/etc/letsencrypt/live/aa/aa/aa"

WSGIProcessGroup macelleria_sito1

Alias /robots.txt /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/static/robots.txt

Alias /favicon.ico /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/static/favicon.ico

Alias /static/ /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/static/

<Directory /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/static>

Require all granted

</Directory>

Alias /media/ /opt/bitnami/projects/macelleria_sito1/media/

<Directory /opt/bitnami/projects/macelleria_sito1/media>

Require all granted

</Directory>

WSGIScriptAlias / /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/macelleria_progetto/wsgi.py

<Directory /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/macelleria_progetto>

<Files wsgi.py>

Require all granted

</Files>

</Directory>

</VirtualHost>

This is the key line from the traceback - for whatever reason, it’s not finding your settings.py file.

Is your settings.py file in /opt/bitnami/projects/macelleria_sito1/macelleria_progetto/ ?
If not, what directory is it located in? (According to the error message, that’s the directory where it’s expecting to find it.)

Hi @KenWhitesell

I’m having the similar issue with lightsail bitnami installation for some reason it’s recognizing the packages. settings.py file is located at /opt/bitnami/projects/WEBSITE/WEBSITE/settings.py and I’m using the the “System Packages Approach A”.

However in my case it is able to recoganize the settings.py file but not the installed packages. Seems to be a problem with apache’s virtual server and it is looking into the some directory where they are not. Also, I did not activated or created any sort of virtual server so far to install packages. As the docs didn’t mentioned any specific like activating anything apart from editing the apache conf files. [Deploy a Django project].

Moreover, just for some more context about the system running sudo pip did solves the problem but probably become a problem later on.

LOGS:

[Thu Aug 04 15:35:38.816320 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]     self._wrapped = Settings(settings_module)
[Thu Aug 04 15:35:38.816326 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "/opt/bitnami/python/lib/python3.8/site-packages/django/
conf/__init__.py", line 170, in __init__
[Thu Aug 04 15:35:38.816332 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Aug 04 15:35:38.816338 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "/opt/bitnami/python/lib/python3.8/importlib/__init__.py
", line 127, in import_module
[Thu Aug 04 15:35:38.816343 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]     return _bootstrap._gcd_import(name[level:], package, level)
[Thu Aug 04 15:35:38.816349 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "<frozen importlib._bootstrap>", line 1014, in _gcd_impo
rt
[Thu Aug 04 15:35:38.816356 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "<frozen importlib._bootstrap>", line 991, in _find_and_
load
[Thu Aug 04 15:35:38.816362 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "<frozen importlib._bootstrap>", line 975, in _find_and_
load_unlocked
[Thu Aug 04 15:35:38.816369 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "<frozen importlib._bootstrap>", line 671, in _load_unlo
cked
[Thu Aug 04 15:35:38.816388 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "<frozen importlib._bootstrap_external>", line 843, in e
xec_module
[Thu Aug 04 15:35:38.816395 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "<frozen importlib._bootstrap>", line 219, in _call_with
_frames_removed
[Thu Aug 04 15:35:38.816401 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]   File "/opt/bitnami/projects/core/core/settings.py", line 4, i
n <module>
[Thu Aug 04 15:35:38.816406 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ]     from decouple import config
[Thu Aug 04 15:35:38.816424 2022] [wsgi:error] [pid 13925:tid 139629589731072] [remote ] ModuleNotFoundError: No module named 'decouple'

Also, I tried to follow up with this issue: [airflow] module not found · Issue #2305 · bitnami/charts · GitHub which is the only search result I got apart from this thread.

Please clarify what you mean here.

Are you saying you are no longer having this problem? If you aren’t, why do you think this would become a problem later on?

Thanks for the reply.

Yes, kind of. I mean when I installed the packages with sudo privileges “sudo pip install ******”, it worked fine. However, pip also warned it’s not a good practice to install them with sudo as it may create some conflicts. That’s why I mentioned it.

The issue here is that the operating system relies upon Python for its own internal functions.

If you update global packages using pip, you can cause problems with conflicts with the packaged versions of those libraries (if any).

So you have two basic choices. You can either look for an os-packaged version of that particular library, or you could change your configuration to use a virtualenvironment and install all the packages your need there.

1 Like

Thanks @KenWhitesell for the help. I’d probably moved to custom installation instead of using bitnami. For some reason I always find it complicated to use bitnami installs, even though they are meant ease everything.

+1