python not in command line even though it is in path

40,237

Solution 1

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!

Solution 2

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.

Solution 3

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.

Share:
40,237

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    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

    • hbprotoss
      hbprotoss almost 11 years
      echo %PATH% What's the result?
    • Admin
      Admin almost 11 years
      C:\Python27;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\‌​System32\Wbem;%SYSTE‌​MROOT%\System32\Wind‌​owsPowerShell\v1.0\;‌​Python27\Scripts;C:\‌​OpenSSL-Win32;
    • LF00
      LF00 over 4 years
      Refer to this post
  • Admin
    Admin almost 11 years
    I don't seem to have a python.exe file, only pythonw.exe. Is this the problem? It's not in my recycle bin so I haven't accidentally deleted it.
  • Philippe Schweitzer
    Philippe Schweitzer almost 11 years
    The output is the same ''python' is not recognized as an internal or external command...'
  • janos
    janos almost 11 years
    I don't have a windows with me right now, but I'm pretty sure there should be a python.exe, and if you can't find it then something's wrong. Try to reinstall it.
  • Saullo G. P. Castro
    Saullo G. P. Castro almost 11 years
    could you check if you have python.exe inside this folder c:\Python27
  • Frank Osterfeld
    Frank Osterfeld almost 11 years
    PYTHONPATH won't help with finding the python.exe executable.
  • DavidPostill
    DavidPostill almost 5 years
    Please quote the essential parts of the answer from the reference link(s), as the answer can become invalid if the linked page(s) change.
  • person27
    person27 over 3 years
    Seems to be paramount that Python37\Scripts\ is present. +1