![Fehlerhafter Interpreter für Conda, Django, Gunicorn und Supervisor: Keine solche Datei oder kein solches Verzeichnis](https://rvso.com/image/756784/Fehlerhafter%20Interpreter%20f%C3%BCr%20Conda%2C%20Django%2C%20Gunicorn%20und%20Supervisor%3A%20Keine%20solche%20Datei%20oder%20kein%20solches%20Verzeichnis.png)
Ich verfolge dasLernprogrammum meine Django-App bereitzustellen, habe aber meine ausführbare Datei so geändert, /var/www/my_django_project/bin/gunicorn_start
dass sie meine Conda-Umgebung statt der virtuellen Umgebung verwendet.
CONDA_SRC=/home/justin/anaconda3/etc/profile.d/conda.sh
GUNICORN=/home/justin/anaconda3/pkgs/gunicorn-20.0.4-py38_0/bin/gunicorn
...
source $CONDA_SRC
conda activate myenv
Bei der Ausführung sudo bin/gunicorn_start
erhalte ich:
“starting backend”
bin/gunicorn_start: /home/justin/anaconda3/pkgs/gunicorn-20.0.4-py38_0/bin/gunicorn: /opt/anaconda1anaconda2anaconda3/bin/python: bad interpreter: No such file or directory
bin/gunicorn_start: line 25: /home/justin/anaconda3/pkgs/gunicorn-20.0.4-py38_0/bin/gunicorn: Success
und mein supervisor.log zeigt:
supervisor: couldn't exec /var/www/my_django_project/bin/gunicorn_start: EACCES
supervisor: child process was not spawned
Antwort1
Ich habe dies behoben, indem ich die Basis meines GUNICORN
Pfads in das Verzeichnis geändert habe, das die Binärdateien meiner Conda-Umgebung enthält. Dies kann mit gefunden werden, which python
während Ihre Conda-Umgebung aktiviert ist, was Folgendes ergibt: /home/justin/anaconda3/envs/production/bin/python
. Verwenden Sie /home/justin/anaconda3/envs/production/bin/gunicorn
.
bin/gunicorn_start
ausführbar:
#!/bin/bash
NAME=”backend”
DJANGODIR=/var/www/my_django_project/backend
SOCKFILE=/var/www/my_django_project/run/gunicorn.sock
USER=django
GROUP=my_django_project
NUM_WORKERS=3
DJANGO_SETTINGS_MODULE=backend.settings
DJANGO_WSGI_MODULE=backend.wsgi
CONDA_SRC=/home/justin/anaconda3/etc/profile.d/conda.sh
GUNICORN=/home/justin/anaconda3/envs/production/bin/gunicorn
echo “starting backend”
cd $DJANGODIR
source $CONDA_SRC
conda activate myenv
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR
exec $GUNICORN
${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--user=$USER --group=$GROUP \
--bind=unix:$SOCKFILE \
--log-level=debug \
--log-file=-
Meine Supervisor-Konfiguration fehlte auch sh
im command
Argument und meine Supervisor-Konfiguration verwendete die falsche Erweiterung. Stellen Sie sicher, dass die Erweiterung ist .conf
. Hier ist meine aktualisierte django.conf
:
[program:django]
command =sh /var/www/my_django_project/bin/gunicorn_start
user = django
stdout_logfile = /var/www/my_django_project/backend/logs/supervisor.log
redirect_stderr = true
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8
Ich hoffe, dies hilft allen anderen, die dieses Problem haben.