I need to write a script to start gunicorn + django site which developed with pyenv the script is something like
#!/bin/bash
pyenv activate .ve
pyenv exec gunicorn config.wsgi:application --name mini2 --workers 8 \
--workers 8 --bind=unix:/tmp/run/mini2.socket \
--log-level=debug --log-file=-
and the error message
2021-12-06 14:09:00 [mini2@s017 mini2]$ ./prodution.sh
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.
2021-12-06 14:09:55 [mini2@s017 mini2]$
I can run the script line by line. so there must be something wrong in the script , but I have no clue what's going wrong.
I had already append couple lines about pyenv in my bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
so is there anyway to activate virtualenv create by pyenv in bash script ? any suggestions ??
update:
according to Failed to activate virtualenv with pyenv
I update my .bashrc
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
#if command -v pyenv 1>/dev/null 2>&1; then
# eval "$(pyenv init -)"
#fi
but still not working.
my test script
#!/bin/bash
pyenv activate .ve
and the error
Failed to activate virtualenv.
Perhaps pyenv-virtualenv has not been loaded into your shell properly.
Please restart current shell and try again.
activate
should only be relevant for interactive shells. Yourpyenv exec
should work without theactivate
. ~/.bashrc is also only used by interactive shells. – Bazarsource .ve/bin/activate
– Kirkwood