"Pre-commit" command is not found by bash but is installed on macOS
Asked Answered
C

7

5

Problem Description

I'm having trouble making commits, when I try to make a commit with the command, for example:

$ git commit -m "add readme"
pre-commit not found. Install pre-commit with the command pip3 install --user pre-commit or follow the steps on official documentation: https://pre-commit.com /#install

Following the steps described in the pre-commit installation documentation I installed by the command:

$ pip install pre-commit

However when I trigger the command the following error occurs:

$ pre-commit --version
bash: pre-commit: command not found

My attempt fails, so I've tried some other solutions for this but they didn't work.

Export bash:

I already tried this solution described that would be to export my ~./bashrc with the command: source ~/.profile but the following error happens:

bash:/Users/pvieira/.profile: No such file or directory

Install using homebrew:

This results in the same error that occurs when manually installing by pip above.

Conny answered 24/6, 2022 at 12:58 Comment(2)
pre-commit would not produce that output so it's something custom that you or your company has set upChiton
Are you using a virtual environment? Maybe pre-commit was installed only inside of a virtual env, but you are doing git commit outside of a virtualenv.Prosaic
C
17

I was able to solve the problem by simply restarting the terminal.

Conny answered 26/6, 2022 at 15:32 Comment(2)
The solution that everyone forgets to do is finally here!Follett
Le sigh. Yep. This was the fix.Olympian
A
8

I have used MacOS. I solved this problem installed pre-commit by brew install pre-commit

Awhirl answered 18/7, 2023 at 13:53 Comment(0)
S
3

Ubuntu suggests installing pre-commit as apt package:

sudo apt install pre-commit
Shout answered 24/3 at 19:23 Comment(0)
B
1

command not found

This error generally means that your shell could not find the an matching executable file in their hash or that the file is not longer located at the previous location. The shell creates a hash of all programs in the PATH environment variable when it loads.

Depending on your shell you can refresh their hash by running hash or rehash.

The reason reloading your shell or terminal fixes the issue is because it, in effect, creates a new hash. Along the same lines, restarting the computer also happens to recreate a new hash.

Bind answered 30/3, 2023 at 16:0 Comment(1)
Thanks for your remark. In my case, I was using a virtual venv and the PATH was not pointing to the right location after venv activation. I suspect that this problem was related to the fact that I move the venv in the past. I recreated the venv to solve the problem and it updated the PATH properly.Larry
A
0

for me the problem was that I used pip install instead of pip3 install which wasn't using the default python version. After adding this to the bash profile and restarting bash it started working

alias python='python3'
alias pip='pip3'
Abamp answered 27/9, 2023 at 12:27 Comment(0)
P
0

If you are using nvm and recently installed a new version of node while uninstalling a previous version, this could be due to nvm default pointing to an old version.

Run the following command to see the current version of nvm default:

nvm ls

And then set nvm default to a version that is installed:

nvm alias default [VERSION]

i.e.

nvm alias default 18.18.0
Petua answered 29/7 at 7:54 Comment(0)
S
-1

I solved this problem by restarting my ubuntu system

Stemware answered 6/9, 2022 at 3:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.