LAhrens
LAhrens

Reputation: 25

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.

Upvotes: 0

Views: 2105

Answers (2)

Jesse McCall
Jesse McCall

Reputation: 53

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!

Upvotes: 0

yoyoyoyo123
yoyoyoyo123

Reputation: 2472

Set the PATH variable

  1. Go to Control Panel/System and Security/System
  2. Click on Advanced System Settings
  3. Go to the Advanced Tab
  4. Click the Environment Variables button at the bottom
  5. In user/system variables section, edit the existing PATH variable with the appropriate python directories.

example

C:\Python3.6;C:\Python3.6\Lib\site-packages\;C:\Python3.6\Scripts\

Upvotes: 1

Related Questions