Advertisement
estarkov

GetPython.vbs

Jun 12th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function GetPythonVersion()
  2.     On Error Resume Next
  3.     Err.Clear
  4.     GetPythonVersion = vbNullString
  5.     Set WshShell = CreateObject("WScript.Shell")
  6.     Set WshExec = WshShell.Exec("python --version")
  7.     If Err.Number = 0 Then ' если питон вообще есть
  8.         Set TextStream = WshExec.StdOut
  9.         Str = vbNullString
  10.         While Not TextStream.AtEndOfStream
  11.             Str = Str & Trim(TextStream.ReadLine()) & vbCrLf
  12.         Wend
  13.         Set objRegExp = CreateObject("VBScript.RegExp")
  14.         objRegExp.Pattern = "(\d+\.?)+"
  15.         objRegExp.Global = True
  16.         Set objMatches = objRegExp.Execute(Str)
  17.         PythonVersion = "0"
  18.         For i=0 To objMatches.Count-1 ' должно быть только одно совпадение
  19.             PythonVersion = objMatches.Item(i).Value
  20.         Next
  21.         GetPythonVersion = PythonVersion
  22.     Else
  23.         Err.Clear
  24.     End If
  25. End Function
  26.  
  27. Function DownloadPython()
  28.     Err.Clear
  29.     Set x = CreateObject("WinHttp.WinHttpRequest.5.1")
  30.     call x.Open("GET", "https://www.python.org/ftp/python/3.5.3/python-3.5.3-amd64-webinstall.exe", 0)
  31.     x.Send()
  32.     Set s = CreateObject("ADODB.Stream")
  33.     s.Mode = 3
  34.     s.Type = 1
  35.     s.Open()
  36.     s.Write(x.responseBody)
  37.     call s.SaveToFile("python-3.5.3-amd64-webinstall.exe", 2)
  38.     DownloadPython = "python-3.5.3-amd64-webinstall.exe"
  39. End Function
  40.  
  41. Function InstallPython()
  42.     InstallPython = False
  43.     PythonVersion = GetPythonVersion()
  44.     If Mid(PythonVersion, 1, 3)="3.5" Then
  45.         InstallPython = True
  46.     Else
  47.         txt = vbNullString
  48.         If Len(PythonVersion) > 0 Then
  49.             txt = "Обнаружена не подходящая версия питона"
  50.         Else
  51.             txt = "Питон не установлен"
  52.         End If
  53.         If MsgBox(txt & vbCrLf & "Скачать подходящую версию?", 4) = 6 Then
  54.             MsgBox("Не забудьте поставить галочку в пункте 'Add Python 3.5 to PATH'")
  55.             Set WshShell = WScript.CreateObject("WScript.Shell")
  56.             WshShell.Run DownloadPython(), 0, True
  57.             MsgBox("установка питона завершена, запустите скрипт повторно для продолжения установки")
  58.         End If
  59.     End If
  60. End Function
  61.  
  62. If InstallPython() Then
  63.     Set WshShell = WScript.CreateObject("WScript.Shell")
  64.     'установка tensorflow
  65.     WshShell.Run "pip install --upgrade pip", 1, True
  66.     WshShell.Run "pip install --ignore-installed --upgrade https://ci.tensorflow.org/view/Nightly/job/nightly-win/DEVICE=cpu,OS=windows/lastSuccessfulBuild/artifact/cmake_build/tf_python/dist/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl", 1, True
  67.     WshShell.Run "pip install -U pip setuptools", 1, True
  68.     WshShell.Run "pip install matplotlib" , 1, True
  69.     WshShell.Run "pip install jupyter" , 1, True
  70.     If MsgBox("Всё готово, запустить Jupyter notebook?", 4) = 6 Then
  71.         WshShell.Run "jupyter notebook" , 1, False
  72.     End If
  73. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement