Search code examples
pythoncmdwindows-10startupreinstall

How to open python in cmd with the 'python' command in stead of py -3


It is a minor issue, but since I reinstalled python (3.6.3 on windows 10), it no longer starts using the python command in the command prompt. Instead I have to use the py -3 command now.

The error:

'python' is not recognized as an internal or external command,
operable program or batch file.

Since it is probably the most common way to use python in commands on forums, it becomes quite annoying to change it every time.

Thank you in advance.


Solution

  • As, others have said -- you could just add the python directory containing the executable to the PATH... I just want to give this as an extra option.

    This is a general solution for any type of program or executable you'd like to run with a custom name.

    I created an "Aliases" folder in my account C:\Users\{Your Account Name}\Aliases.

    In that folder, I keep useful .bat scripts.

    Just make a script called "python" and, in that script, put the path of your python.exe.

    So, for example, this would be your entire bat file (named python.bat):

    @echo off
    echo .
    C:\Python36\python.exe
    

    if you want to be able to add args to your command, do the same but replace the execution line with the follows:

    C:\Python36\python.exe %1 %2 %3 %4 %5 %6
    

    That will give you the ability to add up to 6 arguments. This is helpful if you're doing python pip commands directly from the command line.

    After you create this file, simply add the folder to your PATH variable (Start -> Type Edit the Environment Variables for your account -> Click PATH -> click Edit -> Append the location of your "Aliases" folder to the PATH, using a semi-colon to separate it from the rest. -> Click OK and OK once again.) From now on, you don't have to worry about the PATH variable, just add more bat files and you're good to go!