Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python command not working in command prompt

When I type python into the command line, the command prompt says python is not recognized as an internal or external command, operable program, or batch file. What should I do?

Note: I have Python 2.7 and Python 3.2 installed on my computer.

like image 496
Rohit Rayudu Avatar asked Nov 28 '12 01:11

Rohit Rayudu


People also ask

Why is my Python not working in command prompt?

The “Python is not recognized as an internal or external command” error is encountered in the command prompt of Windows. The error is caused when Python's executable file is not found in an environment variable as a result of the Python command in the Windows command prompt.

How do I enable Python in CMD?

Open Command Prompt and type “python” and hit enter. You will see a python version and now you can run your program there.

Why is Python not working Windows 10?

The most common cause of this error is the PYTHONPATH and PYTHONHOME environment variables. You can see what environment variables are set by the "set" command.

Why does py work but not Python CMD?

py is itself located in C:\Windows (which is always part of the PATH ), which is why you find it. When you installed Python, you didn't check the box to add it to your PATH , which is why it isn't there. In general, it's best to use the Windows Python Launcher, py.exe anyway, so this is no big deal.


2 Answers

I have installed the latest Python for Win10 from Releases for Windows. Just typing py in the Command Prompt Window starts Python.

Microsoft Windows [Version 10.0.15048] (c) 2017 Microsoft Corporation. All rights reserved.  C:\Users\sg7>py Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>`enter code here` 

Testing:

>>> print("hello!") hello! >>> 

Please be aware that in my case Python was installed in C:\Users\sg7\AppData\Local\Programs\Python\Python36> directory

C:\Users\sg7\AppData\Local\Programs\Python\Python36>dir  Volume in drive C is Windows7_OS  Volume Serial Number is 1226-12D1   Directory of C:\Users\sg7\AppData\Local\Programs\Python\Python36  08/05/2018  07:38 AM    <DIR>          . 08/05/2018  07:38 AM    <DIR>          .. 12/18/2017  09:12 AM    <DIR>          DLLs 12/18/2017  09:12 AM    <DIR>          Doc 12/18/2017  09:12 AM    <DIR>          include 12/18/2017  09:12 AM    <DIR>          Lib 12/18/2017  09:12 AM    <DIR>          libs 10/03/2017  07:17 PM            30,334 LICENSE.txt 10/03/2017  07:17 PM           362,094 NEWS.txt 10/03/2017  07:15 PM           100,504 python.exe 10/03/2017  07:12 PM            58,520 python3.dll 10/03/2017  07:12 PM         3,610,776 python36.dll 10/03/2017  07:15 PM            98,968 pythonw.exe 08/05/2018  07:38 AM           196,096 Removescons.exe 08/05/2018  07:38 AM            26,563 scons-wininst.log 08/05/2018  07:38 AM    <DIR>          Scripts 12/18/2017  09:12 AM    <DIR>          tcl 12/18/2017  09:12 AM    <DIR>          Tools 06/09/2016  11:53 PM            87,888 vcruntime140.dll                9 File(s)      4,571,743 bytes               10 Dir(s)  20,228,898,816 bytes free 

When I am at C:\Users\sg7> directory level python can be invoked by typing AppData\Local\Programs\Python\Python36\python

C:\Users\samg>AppData\Local\Programs\Python\Python36\python Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 18:11:49) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 

Newer Python 3.7 will be installed at: C:\Users\YourUserNameHere\AppData\Local\Programs\Python\Python37

If you wish you can add to your path environment variable: %USERPROFILE%\AppData\Local\Programs\Python\Python36

like image 180
sg7 Avatar answered Oct 16 '22 09:10

sg7


It finally worked!!!

I needed to do things to get it to work

  1. Add C:\Python27\ to the end of the PATH system variable
  2. Add C:\Python27\ to the end of the PYTHONPATH system variable

I had to add these to both for it to work.

If I added any subdirectories, it did not work for some reason.

Thank you all for your responses.

like image 29
Rohit Rayudu Avatar answered Oct 16 '22 10:10

Rohit Rayudu