python not in command line even though it is in path

When I type 'python' at the command line it says ''python' is not recognized as an internal or external command...'

I have Python in both User and System paths. In the past I have been able to run python from the command line, but suddenly today I can't.

I'm using Windows 7 32-bit.

Does anyone know what the problem could be?

Thanks

4

8 Answers

This could be a duplicate answer, but the following steps has worked for me.

Note: This is in the case of Anaconda is installed instead of vanilla Python in Windows environment.

Under System variables:

  1. Create a variable

PYTHONHOME = C:\Users\username\Anaconda3

  1. Add the below 2 entries under PATH system variable:

%PYTHONHOME%

C:\Users\username\Anaconda3\Scripts

  1. Close the command prompt if opened earlier and try any python command (Note: no need to restart the OS):

example: python --version
output: Python 3.7.1

Hope this was useful. Cheers!

The python install directory on Windows should have the following files (ignore the pyscopg and pillow files):

Python directory listing

Your PATH environment variable should be like the below if you have install Python2 at the default location:

PATH=%PATH%;C:\Python27\;C:\Python27\Scripts\

You should also have the following in PATHEXT:

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

I noticed in your environment variables you have Python27\Scripts; which is not correct. Try fixing that, and you'll have to close any command prompts if you change any environment variables. If the settings are as the above and you still can't run Python, do a re-install.

1

Lets assume that you installed python in the default location.

try adding this into your system environments.

name : PYTHONPATH
value: C:\Python27\;C:\Python27\Lib;C:\Python27\include;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\Lib\site-packages

Note: when you create a PYTHONPATH environment variable it might effect some other application to forcefully use this version of python instead their own.

1

This seems to be a problem in the PATH environment variable. To confirm that, in cmd try the following:

If you are using Python 2.7:

SET PATH=%PATH%;C:\Python27

If you are using Python 3.3:

SET PATH=%PATH%;C:\Python33

And then: python something

2

python is clearly NOT in your PATH variable. You can confirm this by looking at the output of echo %path%.

Keep in mind that after editing the PATH variable using the control panel, you have to open a new terminal, as the setting will NOT be updated in existing terminals.

Another possibility is that you added the wrong path to the PATH variable. Verify it.

The bottom line is, if the directory of your python.exe is really in PATH, then running python will really work.

2

Try closing the command prompt window and opening again, then trying. Worked for me.

Most common mistake!!

Developers forget to set this "C:\Python27\" in PATH variable assuming "C:\Python27\Lib" is enough.

Both path should be present

Watch this video to install python correctly it was very helpful to me....

How to Install Python Correctly

1

You Might Also Like