Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Pycharm precommits fix


We are using for hooks and this is a really annoying issue This is how I solved it for now (linux only but can be ported to windows) The only requirement is to be in your root folder with the virtualenv activated when you install the hooks this is my shell script in /usr/bin/


pre-commit install
mv .git/hooks/pre-commit .git/hooks/pre-commit-python

cat <<EOF > .git/hooks/pre-commit
source ${VIRTUAL_ENV}/bin/activate
DIR="\$( cd "\$( dirname "\${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
python \${DIR}/pre-commit-python

chmod +x .git/hooks/pre-commit

This will:

  • call pre-commit install
  • move the installed script to .git/hooks/pre-commit-python
  • replace the pre-commit by a bash script:
  • activate the virtualenv (static full path found at install time)
  • dynamically find the directory of the bash script is running from
  • call pre-commit-python with the virtual env activated

If you add more hooks using .pre-commit-config.yaml or you change the path of your virtualenv just call again 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment