147

So I have recently installed Python Version 2.7.5 and I have made a little loop thing with it but the problem is, when I go to cmd and type python testloop.py I get the error:

'python' is not recognized as an internal or external command

I have tried setting the path but no avail.

Here is my path:

C:\Program Files\Python27

As you can see, this is where my Python is installed. I don't know what else to do. Can someone help?

johnnyRose
  • 7,310
  • 17
  • 40
  • 61
Dave Stallberg
  • 1,503
  • 2
  • 13
  • 13

15 Answers15

358

Try "py" instead of "python" from command line:

C:\Users\Cpsa>py
Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Asif Iqbal
  • 3,581
  • 2
  • 10
  • 2
  • 9
    Confirmed installed python 3.4.2 recently. py command is registered automatically. – Jossi Dec 17 '14 at 10:41
  • 7
    Works! Why python is no good though a lot of sources say it should be used? – Andrejs Sep 27 '15 at 13:23
  • 11
    odd that `py` is setup automatically... yet not `python` ? dafaq? Oh but this answer kind of explains http://stackoverflow.com/questions/32742093/how-to-access-python-from-command-line-using-py-instead-of-python#answer-32742619 - basically `py` allows you to specify what version of python you want, but f you don't specify anything then it chooses the default – Don Cheadle Oct 07 '15 at 02:14
  • 3
    yeah.. same question.. py works for python 3.5.2 but python doesnt work. my environmetal variables are set correctly. Any reason why? – alpha_989 Sep 30 '17 at 23:40
  • superb! But, I think in my organization they are not letting me install sklearn through default distribution. I am getting this error `Failed to establish a new connection: [Errno 11002] getaddrinfo failed',)': /simple/sklearn/` – Ash Upadhyay Jun 14 '18 at 05:17
103

I have found the answer... click on the installer and check the box "Add python to environment variables" DO NOT uninstall the old one rather click on modify....Click on link for picture...

enter image description here

Undo
  • 25,519
  • 37
  • 106
  • 129
Akhilesh
  • 1,132
  • 1
  • 7
  • 11
46

You need to add that folder to your Windows Path:

https://docs.python.org/2/using/windows.html Taken from this question.

14

If you want to see python version then you should use py -V instead of python -V

C:\Users\ghasan>py -V

Python 3.7.1

If you want to go to python's running environment then you should use py instead of python

C:\Users\ghasan>py

Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

Here you can run the python program as:

print('Hello Python')

Hello Python

Gufran Hasan
  • 8,910
  • 7
  • 38
  • 51
  • THANKS! This was my _first_ instinct, but just to be sure, I googled "check python version". Everything came up with "`python -V`". Its been here the whole time. I just removed and added path variables -- who knows _what_ I mistakenly corrupted along the way -- for no reason at all. – Cody Nov 11 '20 at 22:12
12

Firstly, be sure where your python directory. It is normally in C:\Python27. If yours is different then change it from the below command.

If after you install it python still isn’t recognized, then in PowerShell enter this:

[Environment]::SetEnvironmentVariable("Path", "$env:Path;C:\Python27", "User")

Close PowerShell and then start it again to make sure Python now runs. If it doesn’t, restart may be required.

enter image description here

11

Type py -v instead of python -v in command prompt

SashJK
  • 121
  • 1
  • 6
  • This works for me. The python directory is my paths, but python does not work for me in PS. It works in git-bash and cmd, though. – user2233706 Apr 05 '21 at 13:59
8

i solved this by running CMD in administration mode, so try this.

6

I have installed python 3.7.4. First, I tried python in my command prompt. It was saying that 'Python is not recognized command......'. Then I tried 'py' command and it works.

My sample command is:

py hacker.py
Abdus Salam Azad
  • 5,087
  • 46
  • 35
5

Open CMD with administrative access(Right click then run as administrator) then type the following command there:

set PYTHONPATH=%PYTHONPATH%;C:\My_python_lib

Replace My_python_lib with the folder name of your installed python like for me it was C:\python27. Then to check if the path variable is set, type echo %PATH% you'll see your python part in the end. Hence now python is accessible. From this tutorial

SAT
  • 23
  • 3
Black Mamba
  • 13,632
  • 6
  • 82
  • 105
4

I have met same issue when I install Python, and it is resolved when I set a PATH in system, here are the steps.

  • Navigate to "Control Panel" -> "System"
  • Click "Advanced system settings" on the left
  • Click "Environment Variables"
  • Search and click "Path" variable
  • Click "Edit"
  • Add "C:\"to the environment variables field, if you are using Windows7, then separate it by a semicolon from the existing entry. If you are using Windows10, just simply click "New" to add.
  • Reopen the Command Prompt and try enter image description here
Ke Du
  • 49
  • 1
  • You can also use SETX PATH "PATHLOCATION OF TOOL" in CMD. e.g. SETX PATH "%USERPROFILE%\AppData\Local\Programs\Python\PythonXX" – Prayson W. Daniel Dec 13 '17 at 11:05
  • In sixth step, you should say Add "C:\Python34" or "C:\Python27", it is depended by the version of your python – Hzzkygcs Apr 02 '18 at 10:06
1

Option 1 : Select on add environment var during installation Option 2 : Go to C:\Users-> AppData (hidden file) -> Local\Programs\Python\Python38-32(depends on version installed)\Scripts Copy path and add to env vars path.

For me this path worked : C:\Users\Username\AppData\Local\Programs\Python\Python38-32\Scripts

Sapna
  • 391
  • 2
  • 3
  • 19
0

From the Python docs, set the PATH like you did as above.

You should arrange for Python’s installation directory to be added to the PATH of every command window as it starts. If you installed Python fairly recently then the command dir C:\py* will probably tell you where it is installed; the usual location is something like C:\Python27. Otherwise you will be reduced to a search of your whole disk

Use Tools ‣ Find or hit the Search button and look for “python.exe”. Supposing you discover that Python is installed in the C:\Python27 directory (the default at the time of writing), you should make sure that entering the command

Then execute the Python command using the full path name to make sure that works.

iheanyi
  • 424
  • 4
  • 9
0

Another helpful but simple solution might be restarting your computer after doing the download if Python is in the PATH variable. This has been a mistake I usually make when downloading Python onto a new machine.

Kevin
  • 113
  • 2
  • 8
0

If you uninstalled then re-installed, and running 'python' in CLI, make sure to open a new CMD after your installation for 'python' to be recognized. 'py' will probably be recognized with an old CLI because its not tied to any version.

run_the_race
  • 1,344
  • 2
  • 36
  • 62
0

It was a bit more confusing with the Python instructions once SQL Server 2019 was installed with Python. The actual path I find is as follows:

C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64

Scripts run with an Execute command:

Declare @script nvarchar(max)=N'print(11-2)' execute sp_execute_external_script @language = N'Python', @script = @script

There is additional documentation in reference to SQL 2019's version of Python. There is a statement that recommends PIP be used only from a download of sqlmutils-x.x.x.zip located on git (https://www.github.com/Microsoft/sqlmutils) But there is a caveat. Currently this only works for R and not for Python (Anaconda and consequently pip). Python over SQL works but pip is not yet available. (11/25/2019)

Would be great to get an update when this occurs.

Jamie
  • 437
  • 4
  • 15