setup_pip.ps1 1.4 KB

1234567891011121314151617181920212223242526272829
  1. $Version = $env:PYTHON_VERSION
  2. $PythonPath = $env:SETUP_PYTHON_PATH
  3. $Semver = $Version.Split('.')
  4. Write-Output "Setting up pip for python $Version in path $PythonPath"
  5. if (!($Semver[0] -like 'pypy*') -and ([int]$Semver[0] -eq 3 -and [int]$Semver[1] -lt 5)) {
  6. if ([int]$Semver[1] -gt 2) {
  7. Write-Output "Using get_pip.py..."
  8. $VersionNumber = $Semver[0]
  9. $Major = $Semver[1]
  10. $GetPipFile = New-TemporaryFile
  11. Invoke-WebRequest -Uri "https://bootstrap.pypa.io/pip/$VersionNumber.$Major/get-pip.py" -OutFile $GetPipFile
  12. Invoke-Expression -Command "$PythonPath $GetPipFile"
  13. Write-Output "Installing typing for old Python versions..."
  14. Invoke-Expression -Command "$PythonPath -m pip install typing"
  15. Remove-Item $GetPipFile
  16. if ([int]$Semver[1] -eq 4) {
  17. Invoke-Expression -Command "$PythonPath -m pip install --upgrade wheel setuptools"
  18. }
  19. } else {
  20. Write-Output "Pip is not available for version $Version"
  21. Write-Output "Proceed with manual installation at own risk"
  22. }
  23. } else {
  24. Write-Output "Using ensurepip..."
  25. Invoke-Expression -Command "$PythonPath -m ensurepip"
  26. Invoke-Expression -Command "$PythonPath -m pip install --upgrade pip"
  27. Write-Output "Installing wheel and setuptools..."
  28. Invoke-Expression -Command "$PythonPath -m pip install --upgrade wheel setuptools"
  29. }