27

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.

Scott Weldon
  • 9,673
  • 6
  • 48
  • 67
Yakman3
  • 293
  • 1
  • 3
  • 7
  • 2
    `git-bash` and `bash` are 2 absolutely different programs. also, have a look at [this question](http://stackoverflow.com/questions/10681101/git-bash-doesnt-see-my-path) – Aserre Dec 01 '16 at 15:19
  • Are you sure it is called `python3` and not just `python`? – cdarke Dec 01 '16 at 15:20
  • @Aserre I looked at it and ran the 'env|grep PATH' command. It returned the two python paths mentioned above in the regular PATH section. – Yakman3 Dec 01 '16 at 15:24
  • @cdarke According to the tutorial, python3 is the correct command. I can try python, though – Yakman3 Dec 01 '16 at 15:25
  • what is the name of the executables for python3 ? i.e. is there a `python3.exe` in the `C:\Users\Corey Rigney\AppData\Local\Programs\Python\Python35\Scripts\ ` folder ? Try running the exact name instead – Aserre Dec 01 '16 at 15:26
  • @cdarke Wow, that actually worked! (Why the heck is the tutorial on that wrong?) Thank you! – Yakman3 Dec 01 '16 at 15:26
  • 1
    The python executable is sometimes called `python3` on some platforms, where the default (`python`) is the old python 2. OS X, for example. – cdarke Dec 01 '16 at 15:29
  • @cdarke Does that mean that I installed this using the wrong version of python? To my knowledge, no other version of python or pip is installed on my computer. – Yakman3 Dec 01 '16 at 15:30
  • 1
    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. – cdarke Dec 01 '16 at 15:34
  • @cdarke Good to know, and thank you for your help! (Since I'm kind of a noob to this site, how do I set yours as the answer? – Yakman3 Dec 01 '16 at 15:39
  • @Yakman3: you can't. Don't worry about it, glad to help. Have fun! – cdarke Dec 01 '16 at 15:40
  • @cdarke: Rather than say "you can't", why not post your solution as an answer? Yes it was a simple fix, but I think [your previous comment](//stackoverflow.com/questions/40914108/bash-python3-command-not-found-windows-discord-py#comment69041347_40914108) has enough information to make it worth posting as an answer. – Scott Weldon Dec 01 '16 at 19:04
  • Entered as an answer. Apologies @ScottWeldon for not doing it sooner, I was pushed for time. – cdarke Dec 02 '16 at 11:44
  • @cdarke No prob; thanks! – Scott Weldon Dec 02 '16 at 17:14
  • @Yakman3: You can now accept the answer that cdarke posted by [clicking the checkmark next to the answer](//stackoverflow.com/help/accepted-answer). – Scott Weldon Dec 02 '16 at 17:21

7 Answers7

60

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.

Prabah
  • 807
  • 6
  • 12
  • That helped me just copy paste in the same place and rename it as "python3.exe", now in the command prompt you can check python3 – Ibrahim Tayseer Jul 17 '19 at 13:21
  • 2
    Worked for me in 2019 – Callat Nov 03 '19 at 21:30
  • 1
    Fixed in less than 10 seconds. Appreciate it! Win10, VS code, Python 3.8 – Vaggelis Manousakis Jul 18 '20 at 16:33
  • 1
    such a simple yet beautiful solution – Younes El Ouarti Mar 23 '21 at 08:10
  • 3
    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](https://stackoverflow.com/a/67445942/971141) (a pointer) to it. – David Ferenczy Rogožan May 08 '21 at 09:26
40

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.

cdarke
  • 42,728
  • 8
  • 80
  • 84
  • May I ask, I have installed and checked that I have Python version 3.6.5 within my Windows 10 system (checked from cmd with `python --version`). Now I need to run a python file that as the authors say should use the `python3.6 baseline.py` in order to execute it. I use git bash to run the code but when typing the aforementioned command I get the error `bash: python3.6: command not found`. If I use simply `python baseline.py` it seems as it tries to run..Is it wrong trying to execute it that way? – user2829319 May 12 '21 at 12:06
  • You only need to run python baseline.py on Windows. That should suffice. – Rahul Mishra Jul 07 '21 at 06:20
21

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

Yorfrank Bastidas
  • 304
  • 1
  • 3
  • 11
8

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:

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
David Ferenczy Rogožan
  • 23,966
  • 9
  • 79
  • 68
5

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
bimlas
  • 2,359
  • 1
  • 21
  • 29
4

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

Jai
  • 2,768
  • 24
  • 20
1

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?

Codian
  • 11
  • 1