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.

7

Best Answer


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.

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.

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

$ python --versionPython 2.7.15

but if I use py

$ py --versionPython 3.8.1

doesn't know why, but It worked

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

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 Bashif [[ "$OSTYPE" =~ ^msys ]]; thenpy -3 $*elsepython3fi

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

None of the solutions above worked for me, however, I was able to find success with Python 3.7 when instead of writing python3 -m pip install discord.py, I wrote C:\InstallPath\python.exe -m pip install discord.py

This probably worked because while the command python3 was not available in cmd, the path to the python core file worked and took the arguments as the python3 command would.

NOTE: The normal python command was not working for me, as I already have 2 installed. Discord for some reason requires 3.5 and above?