Install pre-commit on mac with pip3

We use the pre-commit to check code before commit on git, before we setup the environment, we need to install the pre-commit first, but in…

Install pre-commit on mac with pip3

We use the pre-commit to check code before commit on git, before we setup the environment, we need to install the pre-commit first, but in one of my friend’s computer, we encounter some problems.

Install with brew

I usually install pre-commit with brew with the following command:brew install pre-commit

It works on most machines, but it failed on my friend’s computer.

Install with pip

On the install section on pre-commit , the install command with pip is like below:pip install pre-commit

But it also failed because the python on the machine is python 3, so we use the pip3 to install the command like below:pip3 install pre-commit

But another problem is that we don’t know where the command was installed, use pip3 show pre-command , it also didn’t print the install path of the pre-command command, I tried on another machine, also didn’t find the install path, and finally find the pre-command command exists on ~/Library/Python/3.8/bin, I find we can use the following command to show the python environments:% python3 -m site
sys.path = [
   '/Users/stephen/Library/Python/3.8/bin',
   '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python38.zip',
   '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8',
   '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/lib-dynload',
   '/Users/stephen/Library/Python/3.8/lib/python/site-packages',
   '/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages',
]
USER_BASE: '/Users/stephen/Library/Python/3.8' (exists)
USER_SITE: '/Users/stephen/Library/Python/3.8/lib/python/site-packages' (exists)
ENABLE_USER_SITE: True

Find the real path by accident

Finally, I try to uninstall the pre-commit and install again, and when we try to uninstall the command and get the real install path like below:% pip3 uninstall pre-commit
Found existing installation: pre-commit 2.20.0
Uninstalling pre-commit-2.20.0:
 Would remove:
   /Users/stephen/Library/Python/3.8/bin/pre-commit
   /Users/stephen/Library/Python/3.8/bin/pre-commit-validate-config
   /Users/stephen/Library/Python/3.8/bin/pre-commit-validate-manifest
   /Users/stephen/Library/Python/3.8/lib/python/site-packages/pre_commit-2.20.0.dist-info/*
   /Users/stephen/Library/Python/3.8/lib/python/site-packages/pre_commit/*
Proceed (y/n)?