git filter repo - Python was not found - but it's installed
Asked Answered
Q

3

8

So I'm trying to use git filter-repo for the first time. I've installed Python 3.9. I try to run: git filter-repo --strip-blobs-bigger-than 100M

Each time it fails:

  • Git Bash: git: 'filter-repo' is not a git command.
  • Powershell: Python was not found;
  • CMD: Python was not found;

Any advice on what I'm missing please?

Qualification answered 8/1, 2021 at 9:59 Comment(1)
I realised my initial problem was not putting the file in the git core. However what I'm now seeing is permissions denied to .lock files but I have no idea whyQualification
C
3

Double-check the installation process on newren/git-filter-repo/INSTALL

You must make sure first (in a regular CMD) than git-filter-repo is in your %PATH%.
If you install it through pip, for instance, it should, since the Python folder should be added to your PATH at Python3 installation.

Once that %PATH% is correct (and you see git-filter-repo in it), then git will recognize the filter-repo command.


As commented, there is now a git-filter-repo Homebrew formula, which offers an easier installation process on a Mac.

Clerissa answered 8/1, 2021 at 10:27 Comment(4)
Thank you for the response. Please see my initial comment on the post. I got it to recognise the command however it doesn't seem to change .lock files. I'm not sure why as I'm the creator of them.Qualification
@Qualification Check if another process is using one of those lock files. Try and see if the issue persists after a reboot, when hopefully less processes are active and less likely to keep an handle on those lock files.Clerissa
If working on Mac there is now also a homebrew option I noticed after fiddling with Python2/3, pip2/3, pyenv and Git for too long. Painless: formulae.brew.sh/formula/git-filter-repoPrincipled
@user3271319 Thank you. I have included your comment in the answer for more visibility.Clerissa
S
0

I had the same issue: I put the git-filter-repo under PATH but I got the same 'Python not found' error, even though Python is installed and also under PATH.

I ended up solving this (or worked around it) by changing the she-bang (first comment line at the top) of the downloaded git-fitler-repo file. I changed it from

#!/usr/bin/env python3

to

#!C:\Program Files\Python310\python.exe

(the real Python path on my system) and now it works. It's surprising, because as far as I know Windows does not honor those she-bang lines.

Saylor answered 10/10, 2023 at 8:57 Comment(0)
C
0
  1. python3 in PATH
  2. git-filter-repo file in PATH
    • For Windows users: In the file git-filter-repo, change

      #!/usr/bin/env python3 into #!/usr/bin/env python

      • Reasoning: some Python installations on Windows, e.g. via winget, have python.exe instead of python3.exe.
Collencollenchyma answered 10/6, 2024 at 21:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.