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

Windows用户如何在Git Bash中运行conda base环境的Python脚本

Fixing "/usr/bin/env: ‘python3’: No such file or directory" in Git Bash (Windows + Conda)

Hey there! I’ve run into this exact issue before when using Conda with Git Bash on Windows—let’s get your script running smoothly.

Why This Happens

Git Bash is looking for a python3 executable, but your Conda base environment’s Python is likely named just python.exe (per Windows conventions), and Git Bash might not have Conda’s path properly configured in its environment.


Quick Temporary Fixes (For Immediate Script Run)

  • Option 1: Run the script directly with Conda’s Python
    Skip relying on the shebang line and call Python explicitly in Git Bash:

    python script_1.py
    # Or use the full path if Git Bash can't find `python` yet
    /c/Users/YourUsername/miniconda3/python.exe script_1.py
    

    (Replace YourUsername with your actual Windows username, and adjust the path if you installed Anaconda instead of Miniconda.)

  • Option 2: Update the script’s shebang line
    Open script_1.py and change the first line from:

    #!/usr/bin/env python3
    

    To either:

    #!/usr/bin/env python
    

    Or the full path to your Conda Python executable:

    #!/c/Users/YourUsername/miniconda3/python.exe
    

    Now you can run ./script_1.py as intended.


Permanent Fix (Set Up Git Bash to Recognize Conda Python)

This ensures you never hit this issue again:

  1. Initialize Conda for Git Bash
    In Git Bash, run this command to configure Conda to auto-activate when you open Git Bash:

    conda init bash
    

    Restart Git Bash after running this. You’ll see (base) in your prompt, meaning the base environment is active.

  2. Add a python3 alias (optional but handy)
    If you still want to use python3 commands (or your scripts rely on it), add an alias to your Git Bash profile:

    • Open your .bashrc file in Git Bash:
      nano ~/.bashrc
      
    • Add this line at the bottom:
      alias python3=python
      
    • Save and exit (press Ctrl+O, hit Enter, then Ctrl+X), then restart Git Bash. Now python3 will point directly to your Conda Python.

Verify It Works

Run these commands in Git Bash to confirm everything is set up correctly:

which python  # Should show your Conda base Python path
which python3 # Should either match the above or reference the alias
python --version  # Should display your Conda Python version

内容的提问来源于stack exchange,提问作者faizan hafeez

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.08 13:42:34