1

Im using supervisor to run the django websocket in system startup .

When I start the supervisor it will raise

ModuleNotFoundError: No module named 'django'

in the log file .

Here is supervisor conf:

[fcgi-program:myProject]
environment=HOME="/home/ubuntu/envFiles/myProject/bin"
# TCP socket used by Nginx backend upstream
socket=tcp://0.0.0.0:8000

directory=/home/ubuntu/projects/myProject

command=daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers myProject.asgi:application

# Number of processes to startup, roughly the number of CPUs you have
numprocs=4

process_name=asgi%(process_num)d

autostart=true
autorestart=true

stdout_logfile=/home/ubuntu/logs/project.log
redirect_stderr=true

when i try to restart the supervisor by supervisorctl restart all , it has import module error again.

Error log :

ModuleNotFoundError: No module named 'django'

I think it uses system python path But i defined environment in config file so supervisor must use there environment .

whats the problem ?

How can i set my django environment files in supervisor conf ?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Mehdi bahmanpour
  • 574
  • 7
  • 21
  • Are you using a virtualenv for the project? If so, you'd also need to activate the virtualenv with supervisor – Ozgur Akcali Mar 13 '19 at 12:20
  • @OzgurAkcali Yes im using virtualenv , so how can i activate this ? – Mehdi bahmanpour Mar 13 '19 at 12:21
  • Shouldn't it be `PYTHONPATH` instead of `HOME`? You don't necessarily need to activate the venv is you're using the correct python. Both approaches would work. – dirkgroten Mar 13 '19 at 12:21
  • @dirkgroten tried this before but not worked – Mehdi bahmanpour Mar 13 '19 at 12:22
  • may [this](https://stackoverflow.com/questions/52393668/how-to-config-supervisor-with-django-channels-and-server-daphne) helps? – dirkgroten Mar 13 '19 at 12:24
  • @Mehdibmp can you try adding this line to your supervisor config? environment=PATH="/home/ubuntu/projects/myProject/venv/bin:%(ENV_PATH)s" You'll need to use the path to your virtualenv's bin folder, probably different than what I typed – Ozgur Akcali Mar 13 '19 at 12:27
  • Not quiet sure, but try changing command to `command=source /home/ubuntu/envFiles/myProject/bin/activate && daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers myProject.asgi:application` – Nagesh Dhope Mar 13 '19 at 12:38
  • @OzgurAkcali with these solution supervisor starts but still raises the same error in log file – Mehdi bahmanpour Mar 13 '19 at 13:04
  • @NageshDhope it will raise myProject:asgi1: ERROR (no such file) – Mehdi bahmanpour Mar 13 '19 at 13:05
  • @NageshDhope it will raise myProject:asgi1: ERROR (no such file) – Mehdi bahmanpour Mar 13 '19 at 13:05
  • @Mehdibmp try running the daphne script in your virtualenv. Like; command=/path/to/venv/bin/daphne -u /run/daphne/daphne%(process_num)d.sock --fd 0 --access-log - --proxy-headers myProject.asgi:application – Ozgur Akcali Mar 13 '19 at 13:07
  • Your command has typo myProject.asgi should be myProject.wsgi – Nagesh Dhope Mar 13 '19 at 13:09
  • @OzgurAkcali Thanks , errors gone . there is a problem in logs : 'CRITICAL Listen failure: [Errno 2] No such file or directory: '1572' -> b'/run/daphne/daphne3.sock.lock'' – Mehdi bahmanpour Mar 13 '19 at 13:34

2 Answers2

7

Just try to install package into another python directory, i had same problem with supervisor and it was solved after this:

sudo pip install --target=/usr/local/lib/python3.6/dist-packages <packagename>
vadspb
  • 81
  • 1
  • 5
0

Hello I'm using Ubuntu 22.04.2 LTS on my server and I was facing with the same error. You can download and install packages like this:

sudo python3 -m pip install pandas

It worked for me, I hope my answer will help you!