12

Is it possible to install Python from cmd on Windows? If so, how to do it?

user513951
  • 12,445
  • 7
  • 65
  • 82
madasionka
  • 812
  • 2
  • 10
  • 29
  • 1
    Yes for example u can use this [Non-interactive Installation](https://www.python.org/download/releases/2.5/msi/) – Thaian Sep 05 '17 at 13:29
  • Thanks @Thaian! Works great. – madasionka Sep 07 '17 at 12:40
  • Does this answer your question? [Install Python with cmd or powershell](https://stackoverflow.com/questions/52578270/install-python-with-cmd-or-powershell) – halt9k Mar 02 '23 at 11:14

4 Answers4

14

https://docs.python.org/3.6/using/windows.html#installing-without-ui

Installing Without UI: All of the options available in the installer UI can also be specified from the command line, allowing scripted installers to replicate an installation on many machines without user interaction. These options may also be set without suppressing the UI in order to change some of the defaults.

To completely hide the installer UI and install Python silently, pass the /quiet option. To skip past the user interaction but still display progress and errors, pass the /passive option. The /uninstall option may be passed to immediately begin removing Python - no prompt will be displayed.

All other options are passed as name=value, where the value is usually 0 to disable a feature, 1 to enable a feature, or a path.

Thomas Munk
  • 643
  • 6
  • 24
1

For Windows

I was unable to find a way to Download python using just CMD but if you have python.exe in your system then you can use the below Method to install it (you can also make .bat file to automate it.)

  1. Download the python.exe file on your computer from the official site.

  2. Open CMD and change Your directory to the path where you have python.exe

  3. Past this code in your Command prompt make sure to change the name with your file version In the below code(e.g python-3.8.5.exe)

python-3.6.0.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0

It will also set the path Variables.

Khan Saad
  • 823
  • 1
  • 9
  • 26
1

I have used windows powershell to achieve this..

  1. Download Python Exe File..Feel free to edit 'URI' for the updated version of python & outFile for your preferred windows location

    Invoke-WebRequest -UseBasicParsing -Uri 'https://www.python.org/ftp/python/3.11.0/python-3.11.0-amd64.exe' -OutFile 'c:/veera/python-3.11.0-amd64.exe'

  2. install python via command prompt

    .\python-3.11.0-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0

  3. set python location

    setx /M path "%path%;C:\Program Files\Python311"

    $env:PATH =$env:PATH+";C:\Program Files\Python311"

you're good to use python from command now :)

Veeramani Natarajan
  • 192
  • 2
  • 4
  • 11
0

Assuming that you have python-installer.exe file you can run in in /passive mode in administrator window. Without administrator privileges you will be prompted

Do you want to allow this app to make changes to your device?

Powershell example could be:

$installer = "C:/tmp/python-3.7.6-amd64.exe"
& $installer /passive InstallAllUsers=1 PrependPath=1 Include_test=0
J.Wincewicz
  • 849
  • 12
  • 19
  • umm but it will not automatically set the path variable right? – Khan Saad Jul 28 '20 at 18:55
  • @KhanSaad I do not understand why you downvoted that and based you answer on exactly the same statement. `PATH` will behave the same way in with both flags `/passive` or `/quiet`. If you have noticed different behaviour perhaps command like was not refreshed. – J.Wincewicz Nov 24 '20 at 17:39
  • I am sorry, I was frustrated with a code, Change something in the answer and I will upvote again – Khan Saad Nov 24 '20 at 17:58