3

I have post-receive hook with install command:

pip install -r requirements.txt

After I call git push live master hook calls pip install command but on remote server installing started on system python2.7 instead of python3.6.4 which I specified as global in pyenv. I guess .bashrc with pyenv setup is not called in non-interactive sessions...

so... how to specify python interpreter in git post-receive hook?

Ugly solutions:

  • modify link /usr/bin/python so it points to needed interpreter (and same for pip)
  • specify full path to pip /home/user/.pyenv/.../pip install -r ...

Solved by creating separate virtualenv and adding source path/to/virtualenv/activate to the hook script.

In my case virtualenv created by pyenv had non-executable activate so also needed to make it executable with chmod +x path/to/activate

aiven
  • 3,775
  • 3
  • 27
  • 52

3 Answers3

0

Check if adding a shebang to your post-receive hook script can help

#!/usr/bin/python3

Or:

#!/usr/bin/env python3

The other alternative, described here, is to define pip3, which explicitly reference a pip installed with python3.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

How about explicitly calls python3 to invoke pip?

python3 -m pip install -r requirements.txt
Hai Vu
  • 37,849
  • 11
  • 66
  • 93
0

By copying the lines that make pyenv work right into the post-receive hook script before using Python the first time, pyenv can be used as expected.

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