【问题标题】:Getting pkg_resources.DistributionNotFound: The 'supervisor==3.2.0' distribution was not found and is required by the application?获取 pkg_resources.DistributionNotFound: 'supervisor==3.2.0' 分发未找到并且是应用程序需要的?
【发布时间】:2019-10-19 23:33:48
【问题描述】:

尝试通过主管运行 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=-

【问题讨论】:

    标签: django gunicorn supervisord


    【解决方案1】:

    你需要通过 pip 安装 supervisor:

    pip install supervisor==3.2.0
    

    【讨论】:

    • 这是正确的答案。
    【解决方案2】:

    可能安装了多个不同版本的 supervisorctl。我在安装 python3.5 并将 python3 设置为默认 python 版本时遇到了同样的问题。我尝试了以下并解决了这个问题。

    1. whereis supervisorctl 将获取所有主管版本的位置。
    2. 检查文件 supervisorctl 的输出位置。 ablove supervisorctl 二进制文件之一可以正确执行。删除另外一个,问题就解决了。

    【讨论】:

      【解决方案3】:

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

      1. 安装 Python 2.7。 (由于 supervisor 支持 2.* 并且对 3.* 的支持仍在开发中) https://askubuntu.com/a/981279

      2. 转到 /usr/bin/supervisorctl 文件。

      3. 将第一行更新为

      !/usr/bin/python2

      让主管使用安装的python 2.7而不是python3。

      Supervisorctl updated file

      1. 重新运行 supervisorctl 命令。

      【讨论】:

      • 执行此操作后出现此错误unix:///var/run/supervisor.sock refused connection
      • 希望这会有所帮助。 stackoverflow.com/q/20067116/8438982
      • 在我的 CentOS 7 中,文件是 /usr/bin/supervisord。相同的修复
      【解决方案4】:

      使用apt安装supervisor -

      apt install supervisor -y
      

      生成主管配置文件 -

      sudo su - && echo_supervisord_conf > /etc/supervisor/supervisord.conf
      

      将 gunicorn 条目添加到配置文件的末尾 -

      [program: gunicorn]
      command=/gunicorn_start.sh
      

      gunicorn_start.sh 是您的 gunicorn 脚本。

      重启supervisord服务-

      sudo service supervisor restart
      

      使用 supervisorctl 使用 -

      sudo supervisorctl
      

      【讨论】:

        【解决方案5】:

        就我而言,我安装了 gunicorn3 而不是 gunicorn,问题就消失了。

        sudo apt install gunicorn3
        

        【讨论】:

          猜你喜欢
          • 2019-05-12
          • 1970-01-01
          • 2018-12-25
          • 2016-11-29
          • 1970-01-01
          • 2021-11-26
          • 1970-01-01
          • 1970-01-01
          • 2019-11-12
          相关资源
          最近更新 更多