Windows bash python command not found

Duplicating the Python 3 executable python.exe and renaming it to python3.exe suggested in another answer is a terrible idea, please don’t do it, because you would have to repeat it every time you upgrade Python to a newer version and it’s likely that you’ll forget it and you’ll be surprised that your Python is broken after the upgrade.

I suggest the following simple setup.

Solution: Symbolic Link python3.exe

Just create a symbolic link named python3.exe in a directory which is in your PATH environment variable (but which is not under the Python 3 installation directory) pointing to the Python 3 executable python3/python.exe. The symbolic link stays there and keeps pointing to the correct executable even if you upgrade the Python (since it’s outside the Python 3 installation directory, it’s not affected even when the whole directory of an outdated Python is deleted and a new Python is placed there).

It’s very easy to prepare:

  1. Execute an elevated Powershell Core (pwsh.exe), Powershell (powershell.exe), or Windows command shell (cmd.exe)
  2. Decide where you want to create the symbolic link:
    • Pick a directory already in your PATH environment variable (use echo $env:PATH in Powershell or echo %PATH% in cmd.exe to print the variable contents)
    • Add any directory you like to the PATH variable (see below)
  3. Navigate to the directory you chose in the previous step and create there a symbolic link named python3.exe pointing to the Python 3 executable (the target parameter), both paths may be absolute or relative:
    • in Powershell, use the New-Item command with the -Type SymbolicLink option:

      New-Item -Type SymbolicLink -Path python3.exe -Target c:\<Python3-installation-directory>\python.exe

    • in cmd.exe, use the mklink command:

      mklink python3.exe c:\<Python3-installation-directory>\python.exe

Now, if you execute python3 or python3.exe from any directory, Windows searches it in the current directory and then all directories in your PATH environment variable. It finds the symbolic link you have created which «redirects» it to the Python 3 executable and Windows executes it.

Notes

Which version executes python command?

What Python version is being executed by the command python when both Python 2 and 3 are installed, depends on the order of Python directories in the PATH environment variable.

When you execute a command and it’s not being found in the current working directory, Windows iterates through all directories in the PATH variable while keeping the order as they’re listed there and executes the first executable whose name matches the command (and it stops the searching).

So, when your PATH variable contains Python installation directories in the order c:\dev\python2\;c:\dev\python3;..., then the python command executes python.exe in the c:\dev\python2\ because it was found first.

The order depends on the order in which you have installed both Python versions. Each installation adds (if you check that option) its instalation directory at the beggining of PATH, so the most recently installed version will be executed when you execute just python. But you can reorder them manually, of course.

pip

There’s no issue with pip, because there’s already an executable named pip3.exe that’s located in a directory automatically added to the PATH during the installation by Python (<installation-root>\Scripts, so just use pip3 for the Python 3’s pip and pip/pip2 for the Python 2’s pip.

Editing Environment Variables

  1. Open the Windows’ About dialog by pressing Win + Pause/Break or right-clicking This PC and selecting Properties
  2. Open the System Properties dialog by clicking the link Advanced system settings on the right side of the Settings dialog
  3. Open the Environment Variables dialog by clicking the button Environment Variables… at the bottom of the System Properties dialog
  4. Here, you can manage user variables and if you have the admin rights then also system variables

Duplicating the Python 3 executable python.exe and renaming it to python3.exe suggested in another answer is a terrible idea, please don’t do it, because you would have to repeat it every time you upgrade Python to a newer version and it’s likely that you’ll forget it and you’ll be surprised that your Python is broken after the upgrade.

I suggest the following simple setup.

Solution: Symbolic Link python3.exe

Just create a symbolic link named python3.exe in a directory which is in your PATH environment variable (but which is not under the Python 3 installation directory) pointing to the Python 3 executable python3/python.exe. The symbolic link stays there and keeps pointing to the correct executable even if you upgrade the Python (since it’s outside the Python 3 installation directory, it’s not affected even when the whole directory of an outdated Python is deleted and a new Python is placed there).

It’s very easy to prepare:

  1. Execute an elevated Powershell Core (pwsh.exe), Powershell (powershell.exe), or Windows command shell (cmd.exe)
  2. Decide where you want to create the symbolic link:
    • Pick a directory already in your PATH environment variable (use echo $env:PATH in Powershell or echo %PATH% in cmd.exe to print the variable contents)
    • Add any directory you like to the PATH variable (see below)
  3. Navigate to the directory you chose in the previous step and create there a symbolic link named python3.exe pointing to the Python 3 executable (the target parameter), both paths may be absolute or relative:
    • in Powershell, use the New-Item command with the -Type SymbolicLink option:

      New-Item -Type SymbolicLink -Path python3.exe -Target c:\<Python3-installation-directory>\python.exe

    • in cmd.exe, use the mklink command:

      mklink python3.exe c:\<Python3-installation-directory>\python.exe

Now, if you execute python3 or python3.exe from any directory, Windows searches it in the current directory and then all directories in your PATH environment variable. It finds the symbolic link you have created which «redirects» it to the Python 3 executable and Windows executes it.

Notes

Which version executes python command?

What Python version is being executed by the command python when both Python 2 and 3 are installed, depends on the order of Python directories in the PATH environment variable.

When you execute a command and it’s not being found in the current working directory, Windows iterates through all directories in the PATH variable while keeping the order as they’re listed there and executes the first executable whose name matches the command (and it stops the searching).

So, when your PATH variable contains Python installation directories in the order c:\dev\python2\;c:\dev\python3;..., then the python command executes python.exe in the c:\dev\python2\ because it was found first.

The order depends on the order in which you have installed both Python versions. Each installation adds (if you check that option) its instalation directory at the beggining of PATH, so the most recently installed version will be executed when you execute just python. But you can reorder them manually, of course.

pip

There’s no issue with pip, because there’s already an executable named pip3.exe that’s located in a directory automatically added to the PATH during the installation by Python (<installation-root>\Scripts, so just use pip3 for the Python 3’s pip and pip/pip2 for the Python 2’s pip.

Editing Environment Variables

  1. Open the Windows’ About dialog by pressing Win + Pause/Break or right-clicking This PC and selecting Properties
  2. Open the System Properties dialog by clicking the link Advanced system settings on the right side of the Settings dialog
  3. Open the Environment Variables dialog by clicking the button Environment Variables… at the bottom of the System Properties dialog
  4. Here, you can manage user variables and if you have the admin rights then also system variables

Solution 1

On Windows the normal name for the python executable is python.exe (console program) or pythonw.exe (for GUI programs).

The python executable is sometimes called python3 on some platforms, where the default (python) is the old python 2. On many UNIX-based (inc. Linux and OS X) systems, python 2 is used by system utilities, changing it could have bad consequences on those platforms, hence the name «python3».

On Windows you should be fine — there are other issues on Windows but you won’t get those unless you try to use more than one python version.

Solution 2

In the python installed("c:\\Installationpath\Python3.6.0") path you will find "python.exe", just copy paste in the same place and rename it as "python3.exe", now in the command prompt you can check python3 command should display your python installation. Don’t forget to open a new terminal.

Solution 3

In windows using git bash, python3 didn’t worked for me:

$ python --version
Python 2.7.15

but if I use py

$ py --version
Python 3.8.1

doesn’t know why, but It worked

Solution 4

Instead of copying the executable, add a script that acts as python3.

A Python 3 script with #!python3 shebang line will fail to run, because python3.exe is not exists on Windows — it can be achieved by py -3.

To solve the problem, add this script as python3 in to your PATH: it will avoke the proper Python command depending on the operating system (works on Windows and Linux as well).

#!/usr/bin/env bash
# Fix problem with `python3` shebang on Windows MSYS Bash

if [[ "$OSTYPE" =~ ^msys ]]; then
  py -3 $*
else
  python3
fi

Solution 5

On Windows 10 you might find that py works where python or python3 doesn’t.

Related videos on Youtube

FIX !!!  bash:python : command not found error

04 : 22

FIX !!! bash:python : command not found error

[Solved] python/pip/pip3 is not recognized as an internal or external command | python command error

07 : 08

[Solved] python/pip/pip3 is not recognized as an internal or external command | python command error

Fixed: Python is not recognized as an internal or external command

03 : 31

Fixed: Python is not recognized as an internal or external command

How to install pip | Fix bash: Pip command not found in (kalilinux ,mint ,Ubuntu) Error solved

02 : 10

How to install pip | Fix bash: Pip command not found in (kalilinux ,mint ,Ubuntu) Error solved

How to Fix Python Was Not Found Run Without Arguments to Install From the Microsoft Store Error

02 : 49

How to Fix Python Was Not Found Run Without Arguments to Install From the Microsoft Store Error

Error Handling in Discord.py | Part 5: Make your own discord bot using Python!

09 : 28

Error Handling in Discord.py | Part 5: Make your own discord bot using Python!

How to Fix - bash: python: command not found error solution? - coder website  | Problem solved | git

02 : 24

How to Fix — bash: python: command not found error solution? — coder website | Problem solved | git

Cogs & Hiding the Token! | How to make a Discord Bot with Python Episode 3

27 : 03

Cogs & Hiding the Token! | How to make a Discord Bot with Python Episode 3

Comments

  • I’ve been trying to configure the discord API discord.py and for the purpose of running the Red-MusicBot on my server. I’ve installed Python 3.5, and added the PATH variables (I clicked the «add Python to PATH» option in install). Here’s what my path variables currently look like:

    C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\Scripts\
    C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\
    

    Those are the only ones related to Python. Now, as part of discord.py’s install process, it wants me to run this command in Git Bash:

    $ git clone https://github.com/Rapptz/discord.py
    $ cd discord.py
    $ python3 -m pip install -U .[voice]
    

    The first two lines work perfectly, but the third line returns:

    bash: python3: command not found
    

    I also cloned pip from GitHub as an attempted fix, although the python install site says it comes packaged with 3.5.

    I’m running windows 10, 64-bit.

    The overall goal of this is to install a discord music bot, if it would help I can post the errors I get when trying to run that.

    • git-bash and bash are 2 absolutely different programs. also, have a look at this question

    • The python executable is sometimes called python3 on some platforms, where the default (python) is the old python 2. OS X, for example.

    • No! You installed 3.5 which is the current stable version. You are on Windows, so I would not expect there to be a python already there. On many UNIX-based (inc. Linux and OS X) systems, python 2 is used by system utilities, changing it could have bad consequences on those platforms, hence the name «python3». On Windows you should be fine — there are other issues on Windows but you won’t get those unless you try to use more than one python version.

  • Worked for me in 2019

  • I have to change the «py -3 $*» line to «python $*» to make it work with conda envs.

  • File «<stdin>», line 1 if [[ «$OSTYPE» =~ ^msys ]]; then ^ SyntaxError: invalid syntax >>> ..

  • I guess it is because you have both pythion2 and python3 installed.

  • Fixed in less than 10 seconds. Appreciate it! Win10, VS code, Python 3.8

  • such a simple yet beautiful solution

  • That’s a really bad suggestion, please don’t do it if you want to avoid issues and wasted time in the future. It’s bad because you would have to repeat it every time you’re upgrading Python to a newer version. It’s likely that you’ll forget it and you’ll end up with a broken or weirdly behaving Python. There are better sugestions in other answers, check them. You can for example create the python3.exe file as suggested in this answer, but instead of the copy of the Python interpreter, it’s just a symbolic link (a pointer) to it.

Recents

Related

I’ve been trying to configure the discord API discord.py and for the purpose of running the Red-MusicBot on my server. I’ve installed Python 3.5, and added the PATH variables (I clicked the «add Python to PATH» option in install). Here’s what my path variables currently look like:

C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\Scripts\
C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\

Those are the only ones related to Python. Now, as part of discord.py’s install process, it wants me to run this command in Git Bash:

$ git clone https://github.com/Rapptz/discord.py
$ cd discord.py
$ python3 -m pip install -U .[voice]

The first two lines work perfectly, but the third line returns:

bash: python3: command not found

I also cloned pip from GitHub as an attempted fix, although the python install site says it comes packaged with 3.5.

I’m running windows 10, 64-bit.

The overall goal of this is to install a discord music bot, if it would help I can post the errors I get when trying to run that.

After installing Python on my fresh MSYS2 I received an error while trying to run it from the console. The bash shell prompted the following output.

bash: python: command not found

Although the Python tool has been successfully installed, the problem is that the builtin shell is unable to locate it.

As you can see from the above screenshot, the Python executable is under the C:\msys64\mingw64\bin directory.

The solution to this problem is to create an alias for Python inside the .bashrc file. Locate the .bashrc file, open it in editing mode with your favorite text editor.

Then add the following lines at the bottom, and save it.

# python and pip alias
alias python=»c:/msys64/mingw64/bin/python3.8.exe»
alias pip=»c:/msys64/mingw64/bin/pip3.exe»

Restart the MSYS2. Now you should be able to run python from the console. The following screenshots show python and pip being being executed directly from the console.

  • Windows automated installation kit for windows 7 and windows server 2008 r2
  • Windows based script host ошибка
  • Windows autoexec bat windows 7
  • Windows aik для windows 7 что это
  • Windows based script host вирус