python - Virtualenv 存在但无法从 bash 脚本访问它

标签 python django bash unix virtualenvwrapper

我正在 debian 服务器上设置一个 django 项目,并安装了 virtualenvwrapper 等。它在命令行中运行良好,但现在我想从脚本中激活它。脚本中的其他一切工作正常,但 virtualenvwrapper 出现错误。

这是我的脚本:

#!/bin/bash

source /usr/local/bin/virtualenvwrapper.sh

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

echo "Starting $NAME"

# Activate the virtual environment
cd $DJANGODIR
workon mark
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 ~/Envs/mark/bin/gunicorn ${DJANGO_WSGI_MODULE}:application \
  --name $NAME \
  --workers $NUM_WORKERS \
  --user=$USER --group=$GROUP \
  --log-level=debug \
  --bind=unix:$SOCKFILE

和我的日志:

Starting mark
ERROR: Environment 'mark' does not exist. Create it with 'mkvirtualenv mark'.
2013-10-20 13:54:28 [31640] [INFO] Starting gunicorn 18.0
2013-10-20 13:54:28 [31640] [DEBUG] Arbiter booted
2013-10-20 13:54:28 [31640] [INFO] Listening at: unix:/root/webapps/mark/run/gunicorn.sock (31640)
2013-10-20 13:54:28 [31640] [INFO] Using worker: sync
2013-10-20 13:54:28 [31661] [INFO] Booting worker with pid: 31661
2013-10-20 13:54:28 [31662] [INFO] Booting worker with pid: 31662
2013-10-20 13:54:28 [31663] [INFO] Booting worker with pid: 31663

任何帮助将不胜感激!我预计使用我的 root 用户是不好的,但这是我第一次。

最佳答案

试试这个来执行你的 bash 脚本:。 ./script.sh

关于python - Virtualenv 存在但无法从 bash 脚本访问它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19478442/

相关文章:

python - 仅捕获由导入直接引起的导入错误

django - 在 POST 后重定向时传递信息

python - 获取类型错误 : unhashable type: 'list' in python dict

python - Cx_Freeze - 如何包含模块

django - 更改最终用户的 postgres 密码

linux - 从 AWS CLI 管道输出到特定行上的现有文件

linux - 如何在 bash 脚本中将所有文件从一个目录复制到另一个目录

linux - 仅列出目录中的数字文件名

python - 如何通过比较两列(达到该值之间的时间)从不同列检索值?

python - 使用 Django Rest Framework 从列表中的对象序列化自定义字段