You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:配置Git Bash终端运行Python时提示‘python: command not found’

Fixing 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.exe part) — 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 .bashrc file 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 .bashrc with 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 $PATH again to confirm the Python path is now included, then test python --version once 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 python3 instead of python by default. If python still fails, try python3 --version to see if that works.

内容的提问来源于stack exchange,提问作者Ryan Reid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 16:22:54