Django 获取pkg#u resources.DistributionNotFound:The';主管==3.2.0';未找到分发,应用程序是否需要分发?

Django 获取pkg#u resources.DistributionNotFound:The';主管==3.2.0';未找到分发,应用程序是否需要分发?,django,gunicorn,supervisord,Django,Gunicorn,Supervisord,试图通过supervisor运行gunicorn脚本时出错。 gunicorn脚本在直接运行时运行良好。 我在ubuntu 16.04上 主管版本: 得到 pkg_resources.DistributionNotFound: The 'supervisor==3.2.0' distribution was not found and is required by the application 跑步时 sudo supervisorctl reread 运行Django应用程序的gunic

试图通过supervisor运行gunicorn脚本时出错。 gunicorn脚本在直接运行时运行良好。 我在ubuntu 16.04上 主管版本: 得到

pkg_resources.DistributionNotFound: The 'supervisor==3.2.0' distribution was not found and is required by the application
跑步时

sudo supervisorctl reread
运行Django应用程序的gunicron脚本:

#!/bin/bash

NAME="applicant_screening"                                  # Name of the application
DJANGODIR=/home/applicant-screening-system/screening_backend             # Django project directory
#SOCKFILE=/home/track_ip/run/gunicorn.sock  # we will communicte using this unix socket
USER=root                                        # the user to run as
#GROUP=webapps                                     # the group to run as
NUM_WORKERS=3                                     # how many worker processes should Gunicorn spawn
DJANGO_SETTINGS_MODULE=screening_backend.settings             # which settings file should Django use
DJANGO_WSGI_MODULE=screening_backend.wsgi                     # WSGI module name

echo "Starting $NAME as `whoami`"

# Activate the virtual environment
cd $DJANGODIR
source /home/screen-env/bin/activate
export DJANGO_SETTINGS_MODULE=$DJANGO_SETTINGS_MODULE
export PYTHONPATH=$DJANGODIR:$PYTHONPATH

# Create the run directory if it doesn't exist
RUNDIR=$(dirname $SOCKFILE)
test -d $RUNDIR || mkdir -p $RUNDIR

# Start your Django Unicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER \
  --bind=0.0.0.0:8000 \
  --log-level=debug \
  --log-file=-

您需要通过pip安装supervisor:

pip install supervisor==3.2.0

可能安装了多个不同版本的supervisorctl。我在安装python3.5并使python3成为默认python版本时遇到了同样的问题。我试着跟着做,解决了这个问题

  • Where is supervisor CTL
    将获取所有supervisor版本的位置
  • 检查文件supervisorctl的输出位置。可以正确执行ablove supervisorctl二进制文件之一。删除另一个,问题就会解决

  • 这是supervisor的要求与安装的python版本之间的版本不匹配。为此,您需要:

  • 安装Python2.7。(因为supervisor支持2.*和3.*仍在开发中)

  • 转到/usr/bin/supervisortl文件

  • 将第一行更新为

  • !/usr/bin/python2 要使主管使用安装的Python2.7而不是python3

  • 重新运行supervisortl命令

  • 使用apt安装监控程序-

    apt install supervisor -y
    
    生成管理器配置文件-

    sudo su - && echo_supervisord_conf > /etc/supervisor/supervisord.conf
    
    [program: gunicorn]
    command=/gunicorn_start.sh
    
    将gunicorn条目添加到配置文件的末尾-

    sudo su - && echo_supervisord_conf > /etc/supervisor/supervisord.conf
    
    [program: gunicorn]
    command=/gunicorn_start.sh
    
    其中gunicorn_start.sh是您的gunicorn脚本

    重新启动supervisord服务-

    sudo service supervisor restart
    
    使用监管者使用-

    sudo supervisorctl
    

    就我的情况而言,我安装了gunicorn3而不是gunicorn,问题就解决了

    sudo apt install gunicorn3
    

    执行此操作后,我出现此错误
    unix:///var/run/supervisor.sock 拒绝连接
    希望这有帮助。