Keywords: Python | Windows | Git Bash | environment variable | discord.py
Abstract: This article addresses the 'bash: python3: command not found' error encountered when installing discord.py using Git Bash on Windows. It analyzes the fundamental differences in Python executable naming between Windows and UNIX systems, proposes using the python command as the primary solution based on the best answer, and supplements with alternative methods like symbolic links. The content covers PATH environment variable configuration, command usage practices, and avoidance of common pitfalls, providing a comprehensive technical guide for developers.
When installing discord.py or other Python projects using Git Bash, developers often encounter the 'bash: python3: command not found' error. This error stems from differences in Python executable naming between Windows and UNIX-based systems. On Windows, Python installations generate an executable named python.exe by default, not python3. In UNIX systems like Linux or macOS, the default python command may point to Python 2 for historical reasons, so python3 is used to explicitly specify Python 3 to avoid breaking system tool dependencies. Windows systems do not require this distinction, and the python command can be used directly.
Problem Analysis and Core Principles
The PATH environment variable plays a crucial role in command execution. When a user types python3 in Git Bash, the system searches for an executable named python3.exe or python3 in the directories listed in PATH. On Windows, Python installations typically add their path (e.g., C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\) to PATH, but the executable is named python.exe, so the python3 command cannot be found. This explains why running python3 -m pip install -U .[voice] fails.
Recommended Solution
Based on best practices, it is recommended to use the python command instead of python3. When installing discord.py, modify the command to python -m pip install -U .[voice]. This leverages the standard naming on Windows without additional configuration. Ensure that the PATH environment variable correctly includes the Python installation directory and its Scripts subdirectory (e.g., C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\ and C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\Scripts\) for command accessibility.
Supplementary Methods and Considerations
Other answers provide alternative approaches, but caution is advised. For example, directly copying and renaming python.exe to python3.exe may temporarily solve the issue, but it can be overwritten during Python upgrades, leading to maintenance difficulties. A better method is to create a symbolic link: create a python3.exe link in a directory within PATH (e.g., a user-defined directory) pointing to the original python.exe. Use PowerShell command New-Item -Type SymbolicLink -Path python3.exe -Target C:\<Python-path>\python.exe or cmd command mklink python3.exe C:\<Python-path>\python.exe. This ensures the link persists and is unaffected by installation upgrades.
Additionally, on Windows, the py command can be used as a Python launcher, e.g., py -m pip install -U .[voice]. This automatically selects the installed Python version, suitable for multi-version environments. However, note that py may not be pre-installed on all systems and depends on Python installation options.
Practical Steps and Conclusion
Developers should first verify PATH configuration: run echo $PATH in Git Bash to check if Python directories are included. If missing, edit environment variables via System Properties to add the relevant paths. When installing discord.py, use python -m pip install -U .[voice], ensuring compatibility and stability. Avoid relying on the python3 command unless explicitly set via symbolic links or other mechanisms.
In summary, the difference in Python naming between Windows and UNIX systems is the root cause of the 'python3: command not found' error. Prioritize using the python command for simplicity, supplemented by symbolic links for enhanced flexibility. By correctly configuring PATH and understanding system-specific traits, developers can efficiently resolve such issues and improve cross-platform development experiences.