求助:配置Git Bash终端运行Python时提示‘python: command not found’
python: command not found in Git Bash Hey there, let's squash that frustrating python: command not found error in Git Bash once and for all! I’ve dealt with this exact headache before, so here’s a step-by-step breakdown to get your Python commands working smoothly:
Step 1: Locate your Python installation path
First, we need to find where Python is actually installed on your Windows machine:
- Open a regular Windows Command Prompt (not Git Bash) and run
where python. You’ll get an output like this:C:\Users\YourUsername\AppData\Local\Programs\Python\Python312\python.exe - Copy the folder path (omit the final
python.exepart) — this is the directory we need to add to Git Bash’s PATH.
Step 2: Check Git Bash’s current PATH
Open Git Bash and run:
echo $PATH
Look through the output for your Python folder path. If it’s missing, that’s the root of the problem.
Step 3: Temporary fix (immediate effect, resets after restart)
If you just need Python working right now without permanent changes, run this in Git Bash (replace the path with your own):
export PATH="$PATH:/c/Users/YourUsername/AppData/Local/Programs/Python/Python312"
Note: Windows drive letters become lowercase with a leading slash in Git Bash (e.g., C:\ becomes /c/), and backslashes turn into forward slashes.
Test it right away with:
python --version
You should see your Python version pop up if it worked.
Step 4: Permanent fix (persists after restarts)
To make this change stick forever, we’ll edit Git Bash’s user configuration file:
- Find or create the
.bashrcfile in your Windows user folder (e.g.,C:\Users\YourUsername\.bashrc). If it doesn’t exist, just create a new plain text file and rename it to.bashrc(make sure file extensions are visible so you don’t end up with.bashrc.txt). - Open
.bashrcwith a text editor (like Notepad or VS Code) and add this line at the bottom (replace the path with your own):export PATH="$PATH:/c/Users/YourUsername/AppData/Local/Programs/Python/Python312" - Save the file, close and reopen Git Bash. Run
echo $PATHagain to confirm the Python path is now included, then testpython --versiononce more.
Alternative: Use an alias (if PATH changes don’t work)
If adding the path still doesn’t do the trick, you can create a direct alias for the Python executable. Add this line to your .bashrc file:
alias python='/c/Users/YourUsername/AppData/Local/Programs/Python/Python312/python.exe'
Save, restart Git Bash, and typing python will now directly call your Python executable.
Quick checks to avoid repeat issues
- When reinstalling Python, make sure to check the "Add Python to PATH" box during installation — this saves you from having to manually add paths later.
- Some Python installs use
python3instead ofpythonby default. Ifpythonstill fails, trypython3 --versionto see if that works.
内容的提问来源于stack exchange,提问作者Ryan Reid

