Python not working in command prompt?

前端 未结 20 1832
迷失自我
迷失自我 2020-11-27 15:25

I type python into the command line, but the command prompt says that python is not recognized as an internal or external command, operable program, or batch fi

相关标签:
20条回答
  • 2020-11-27 15:56

    I wanted to add a common problem that happens on installation. It is possible that the path installation length is too long. To avoid this change the standard path so that it is shorter than 250 characters.

    I realized this when I installed the software and did a custom installation, on a WIN10 operation system. In the custom install, it should be possible to have Python added as PATH variable by the software

    0 讨论(0)
  • 2020-11-27 15:57

    Kalle posted a link to a page that has this video on it, but it's done on XP. If you use Windows 7:

    1. Press the windows key.
    2. Type "system env". Press enter.
    3. Press alt + n
    4. Press alt + e
    5. Press right, and then ; (that's a semicolon)
    6. Without adding a space, type this at the end: C:\Python27
    7. Hit enter twice. Hit esc.
    8. Use windows key + r to bring up the run dialog. Type in python and press enter.
    0 讨论(0)
  • 2020-11-27 15:58

    In Windows 7 python start command in command prompt is

    c:\>python3
    

    but in Windows 10 python start command in command prompt is

      C:\>py
    Python 3.6.3 (v3.6.3:2c5fed8, Oct  3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>>
    
    
    C:\>py --version
    Python 3.6.3
    
    C:\>
    

    But in Windows 10 python3 syntax not work also not given any error.

    Django start command also uses py instead of python3.

    d:\>py manage.py runserver
    
    0 讨论(0)
  • 2020-11-27 15:58

    Just a few comments:

    1. Don't set PYTHONPATH if all you want is to get Python on the PATH. The PYTHONPATH environment variable tells Python where to look for modules to import. Setting it to C:\Python27\ will not accomplish anything useful, although it's probably harmless.

    2. Modifying environment variables (including PATH) from the "Edit System Variables" has no effect on already running processes. This means you have to re-launch cmd.exe for the changes to work. A reboot, however, is not required.

    3. When modifying the PATH, also add the Scripts subdirectory. Or, to put it in other words (and using the previous example): add ;C:\Python27;C:\Python27\Scripts. This will allow you to run scripts like easy_install, pip, virtualenv or sphinx from the command line - once you install those, that is. This is about as UNIX-y as it gets for Windows. (N.B. The Scripts subdirectory is not present after a clean install of Python, but will be created when needed.)

    4. Don't put any additional Lib or DLL directory on the PATH. There's no need, and it might do harm.

    5. If you have installed multiple versions of Python (which isn't all that uncommon) you might be better off not putting any of them on the PATH but instead create different shortcuts to cmd.exe for the different versions which set the PATH for each version. You might also be interested in PEP-397.

    0 讨论(0)
  • 2020-11-27 15:59

    None of these actually worked for me. What you needed to do to really have Python recognized within it's path, is to download the latest version of it only from this website and not other website: https://www.python.org/downloads/

    But be careful while installing; the default installation is set not to add Python's path to the Environmental Variables in the Control Panel if you have a Windows computer, but you should change the setting so that the installation does it, and it will all be done by itself.

    0 讨论(0)
  • 2020-11-27 16:00

    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

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