Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

python

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

like image 644
aiven Avatar asked Apr 01 '26 22:04

aiven


1 Answers

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
like image 132
Gabriel Wolf Avatar answered Apr 04 '26 11:04

Gabriel Wolf