Install Python with cmd or powershell

后端 未结 3 422
执笔经年
执笔经年 2021-01-18 11:52

My question is if you can install python with powershell, cmd, vbs or any other language built into Windows already? If this was already asked please redirect me to the answ

相关标签:
3条回答
  • 2021-01-18 12:23

    The best way to install Python through Windows Command Prompt will be through Chocolatey (Windows Package Manageer).

    Steps to install python 3 will be as follows :-

    1. Open CMD using 'Run as Administrator'.

    2. Download and Install Chocolatey using the following command.

    @"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
    
    1. Download and install python using the following command.
    choco install -y python3
    
    1. You can check the version to verify if Python was successfully installed as follows.
    python --version
    
    0 讨论(0)
  • 2021-01-18 12:43

    You could download the setup you want to install and then install it automatically without using the setup's UI:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    
    Invoke-WebRequest -Uri "https://www.python.org/ftp/python/3.7.0/python-3.7.0.exe" -OutFile "c:/temp/python-3.7.0.exe"
    
    c:/temp/python-3.7.0.exe /quiet InstallAllUsers=0 PrependPath=1 Include_test=0
    

    I don't think it will work without admin privileges though, I tried using InstallAllUsers=0 to install it only for the current user but it is still asking for elevation.

    There are some options you can use when installing it this way, here is the doc: https://docs.python.org/3.6/using/windows.html#installing-without-ui

    0 讨论(0)
  • 2021-01-18 12:44

    You can not install it without administrator privileges. It would be lack of security I guess. What you can use in pipelines for instance is:

    $url = "https://www.python.org/ftp/python/3.7.6/python-3.7.6-amd64.exe"
    $output = "C:/tmp/python-3.7.6-amd64.exe"
    
    if (Test-Path $output) {
        Write-Host "Script exists - skipping installation"
        return;
    }
    
    New-Item -ItemType Directory -Force -Path C:/tmp
    
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    Invoke-WebRequest -Uri $url -OutFile $output
    
    
    & $output /passive InstallAllUsers=1 PrependPath=1 Include_test=0 
    

    But still, Admin rights are required

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