“python” not recognized as a command

后端 未结 12 1875
粉色の甜心
粉色の甜心 2020-11-22 14:01

I just downloaded and installed Python 2.7.2 to my laptop and I am trying to run some sample programs. My laptop is running Windows XP.

When I open a cmd

相关标签:
12条回答
  • 2020-11-22 14:32

    Go to Control Panel / System / "Advanced" tab / Enviromental Variables

    Find variable called PATH in the lower list, and edit it. Add to the end C:\Python27

    Open a new cmd window and try now.

    0 讨论(0)
  • 2020-11-22 14:33

    This is because the Python exec are not in the search path of your operating system. In windows, start CMD. Type in

    setx PATH PythonPath

    where PythonPath is usually C:\Python27 or C:\Python33 or C:\Users\<Your User Name>\AppData\Local\Programs\Python\Python37 depending on your Python version. After restarting the CMD, you should get see outcomes when typing

    Python --version
    
    0 讨论(0)
  • 2020-11-22 14:37

    Python comes with a small utility that fixes this. From the command line run:

    c:\python27\tools\scripts\win_add2path.py
    

    Make sure you close the command window (with exit or the close button) and open it again.

    0 讨论(0)
  • 2020-11-22 14:37

    Make sure you click on Add python.exe to path during install, and select:

    "Will be installed on local hard drive"

    It fixed my problem, hope it helps...

    0 讨论(0)
  • 2020-11-22 14:40

    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.

    0 讨论(0)
  • 2020-11-22 14:52

    Just another clarification for those starting out. When you add C:\PythonXX to your path, make sure there are NO SPACES between variables e.g.

    This:

    SomeOtherDirectory;C:\Python27

    Not this:

    SomeOtherDirectory; C:\Python27

    That took me a good 15 minutes of headache to figure out (I'm on windows 7, might be OS dependent). Happy coding.

    0 讨论(0)
提交回复
热议问题