Score:0

ModuleNotFoundError error when running sudo systemctl status gunicorn

us flag

I'm trying to deploy a Django project on Ubuntu server. I'm folwing this guide.

But I'm facing a problem when I run this command sudo systemctl status gunicorn, I get this error:

● gunicorn.service - gunicorn daemon
     Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Tue 2021-08-31 20:53:12 UTC; 6min ago
TriggeredBy: ● gunicorn.socket
    Process: 1918 ExecStart=/home/houssem/project/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock config.wsgi:application (code=exited, >
   Main PID: 1918 (code=exited, status=3)

Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]:   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]:   File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: ModuleNotFoundError: No module named 'django_extensions'
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1932]: [2021-08-31 20:53:12 +0000] [1932] [INFO] Worker exiting (pid: 1932)
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [WARNING] Worker with pid 1931 was terminated due to signal 15
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [WARNING] Worker with pid 1932 was terminated due to signal 15
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [INFO] Shutting down: Master
Aug 31 20:53:12 ubuntu-20-lts gunicorn[1918]: [2021-08-31 20:53:12 +0000] [1918] [INFO] Reason: Worker failed to boot.
Aug 31 20:53:12 ubuntu-20-lts systemd[1]: gunicorn.service: Main process exited, code=exited, status=3/NOTIMPLEMENTED
Aug 31 20:53:12 ubuntu-20-lts systemd[1]: gunicorn.service: Failed with result 'exit-code'.

When I run this command gunicorn config.wsgi:application --preload -b 0.0.0.0:8000 it works fine and I can access the site using the IP address.

My gunicorn.service and /etc/systemd/system/gunicorn.socket files look like this:

# /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myprojectdir
ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
          --access-logfile - \
          --workers 3 \
          --bind unix:/run/gunicorn.sock \
          myproject.wsgi:application

[Install]
WantedBy=multi-user.target
[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

All the mentioned (in the guide) commands related to gunicorn before this one sudo systemctl status gunicorn work as expected and print the same output as in the guide.

I searched for solutions but I can't figure out how to fix this issue, I'm new to gunicorn.

So please can anyone help me to fix this?

I can provide more detail if the provided information is not enough.

EDIT

About the packages, I've already installed the packages in the virtualenv from a requirements.txt file: pip install -r requirements.txt. Also, I've installed the django-extension globally but still have the same error.

ajgringo619 avatar
de flag
Does this help: https://stackoverflow.com/questions/44289643/importerror-no-module-named-django-extensions. I did not see anywhere in your link that mentioned installing `django-extensions`.
Oussama He avatar
us flag
@ajgringo619 I've already installed all the needed packages in a virtualenv from the requirements file: `pip install -r requirements.txt`
Oussama He avatar
us flag
@Community I add an edit to the question, please could you tell me which points should I highlight?
Laenka-Oss avatar
in flag
You may like to check on how I solved a similar situation: https://stackoverflow.com/a/70945714/8523960
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.