fast_install.sh 30.5 KB
Newer Older
1 2 3 4 5
#!/bin/bash

path='http://paddlepaddle.org/download?url='
#release_version=`curl -s https://pypi.org/project/paddlepaddle/|grep -E "/project/paddlepaddle/"|grep "release"|awk -F '/' '{print $(NF-1)}'|head -1`
release_version=1.2.0
T
tianshuo78520a 已提交
6 7 8 9 10 11 12
python_list=(
"27"
"35"
"36"
"37"
)

13 14 15 16

function use_cpu(){
   while true
    do
17
     read -p "是否安装CPU版本的PaddlePaddle?(y/n)" cpu_option
18
     cpu_option=`echo $cpu_option | tr 'A-Z' 'a-z'`
T
tianshuo78520a 已提交
19
     if [[ "$cpu_option" == "" || "$cpu_option" == "n" ]];then
20
        echo "退出安装中..."
21 22 23
        exit
     else
        GPU='cpu'
24
        echo "将为您安装CPU版本的PaddlePaddle"
25 26 27 28 29
        break
     fi
    done
}

T
tianshuo78520a 已提交
30
function checkLinuxCUDNN(){
31 32 33
   echo
   read -n1 -p "请按回车键进行下一步..."
   echo
T
tianshuo78520a 已提交
34 35 36 37 38 39 40 41 42 43 44
   while true
   do
       version_file='/usr/local/cuda/include/cudnn.h'
       if [ -f "$version_file" ];then
          CUDNN=`cat $version_file | grep CUDNN_MAJOR |awk 'NR==1{print $NF}'`
       fi
       if [ "$CUDNN" == "" ];then
           version_file=`sudo find /usr -name "cudnn.h"|head -1`
           if [ "$version_file" != "" ];then
               CUDNN=`cat ${version_file} | grep CUDNN_MAJOR -A 2|awk 'NR==1{print $NF}'`
           else
45
               echo "检测结果:未在常规路径下找到cuda/include/cudnn.h文件"
T
tianshuo78520a 已提交
46 47
               while true
               do
48 49
                  read -p "请核实cudnn.h位置,并在此输入路径(请注意,路径需要输入到“cudnn.h”这一级):" cudnn_version
                  echo
T
tianshuo78520a 已提交
50
                  if [ "$cudnn_version" == "" ] || [ ! -f "$cudnn_version" ];then
51 52
                        read -p "仍未找到cuDNN,输入y将安装CPU版本的PaddlePaddle,输入n可重新录入cuDNN路径,请输入(y/n)" cpu_option
                        echo
T
tianshuo78520a 已提交
53 54 55 56 57
                        cpu_option=`echo $cpu_option | tr 'A-Z' 'a-z'`
                        if [ "$cpu_option" == "y" -o "$cpu_option" == "" ];then
                            GPU='cpu'
                            break
                        else
58 59
                            echo "请重新输入"
                            echo
T
tianshuo78520a 已提交
60 61 62
                        fi
                  else
                     CUDNN=`cat $cudnn_version | grep CUDNN_MAJOR |awk 'NR==1{print $NF}'`
63
                     echo "检测结果:找到cudnn.h"
T
tianshuo78520a 已提交
64 65 66 67 68 69 70 71 72
                     break
                  fi
                 done
             if [ "$GPU" == "cpu" ];then
                break
             fi
           fi
       fi
       if [ "$CUDA" == "9" -a "$CUDNN" != "7" ];then
73 74 75
           echo
           echo "目前CUDA9下仅支持cuDNN7,暂不支持您机器上的CUDNN${CUDNN}。您可以访问NVIDIA官网下载适合版本的CUDNN,请ctrl+c退出安装进程。按回车键将为您安装CPU版本的PaddlePaddle"
           echo
T
tianshuo78520a 已提交
76 77 78 79 80 81 82
          use_cpu()
          if [ "$GPU"=="cpu" ];then
             break
          fi
       fi

       if [ "$CUDNN" == 5 ] || [ "$CUDNN" == 7 ];then
83 84
          echo
          echo "您的CUDNN版本是: CUDNN$CUDNN"
T
tianshuo78520a 已提交
85 86
          break
       else
87 88 89
          echo
          read -n1 -p "目前支持的CUDNN版本为5和7,暂不支持您机器上的CUDNN${CUDNN},将为您安装CPU版本的PaddlePaddle,请按回车键开始安装"
          echo
T
tianshuo78520a 已提交
90 91 92 93 94 95 96 97
          use_cpu
          if [ "$GPU"=="cpu" ];then
             break
          fi
       fi
   done
}

T
tianshuo78520a 已提交
98
function checkLinuxCUDA(){
T
tianshuo78520a 已提交
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
   while true
   do
       CUDA=`echo ${CUDA_VERSION}|awk -F "[ .]" '{print $1}'`
       if [ "$CUDA" == "" ];then
         if [ -f "/usr/local/cuda/version.txt" ];then
           CUDA=`cat /usr/local/cuda/version.txt | grep 'CUDA Version'|awk -F '[ .]' '{print $3}'`
           tmp_cuda=$CUDA
         fi
         if [ -f "/usr/local/cuda8/version.txt" ];then
           CUDA=`cat /usr/local/cuda8/version.txt | grep 'CUDA Version'|awk -F '[ .]' '{print $3}'`
           tmp_cuda8=$CUDA
         fi
         if [ -f "/usr/local/cuda9/version.txt" ];then
           CUDA=`cat /usr/local/cuda9/version.txt | grep 'CUDA Version'|awk -F '[ .]' '{print $3}'`
           tmp_cuda9=$CUDA
         fi
       fi

       if [ "$tmp_cuda" != "" ];then
118
         echo "检测结果:找到CUDA $tmp_cuda"
T
tianshuo78520a 已提交
119 120
       fi
       if [ "$tmp_cudai8" != "" ];then
121
         echo "检测结果:找到CUDA $tmp_cuda8"
T
tianshuo78520a 已提交
122 123
       fi
       if [ "$tmp_cuda9" != "" ];then
124
         echo "检测结果:找到CUDA $tmp_cuda9"
T
tianshuo78520a 已提交
125 126 127
       fi

       if [ "$CUDA" == "" ];then
128
            echo "检测结果:没有在常规路径下找到cuda/version.txt文件"
T
tianshuo78520a 已提交
129 130
            while true
            do
131
                read -p "请输入cuda/version.txt的路径:" cuda_version
T
tianshuo78520a 已提交
132
                if [ "$cuda_version" == "" || ! -f "$cuda_version" ];then
133
                    read -p "仍未找到CUDA,输入y将安装CPU版本的PaddlePaddle,输入n可重新录入CUDA路径,请输入(y/n)" cpu_option
T
tianshuo78520a 已提交
134 135 136 137 138 139 140 141 142 143
                    cpu_option=`echo $cpu_option | tr 'A-Z' 'a-z'`
                    if [ "$cpu_option" == "y" || "$cpu_option" == "" ];then
                        GPU='cpu'
                        break
                    else
                        echo "重新输入..."
                    fi
                else
                    CUDA=`cat $cuda_version | grep 'CUDA Version'|awk -F '[ .]' '{print $3}'`
                    if [ "$CUDA" == "" ];then
144
                        echo "未能在version.txt中找到CUDA相关信息"
T
tianshuo78520a 已提交
145 146 147 148 149 150 151 152 153 154 155 156 157 158
                    else
                        break
                    fi
                fi
            done
            if [ "$GPU" == "cpu" ];then
                break
            fi
       fi

       if [ "$CUDA" == "8" ] || [ "$CUDA" == "9" ];then
          echo "您的CUDA版本是${CUDA}"
          break
       else
159 160
          echo "目前支持CUDA8/9,暂不支持您的CUDA${CUDA},将为您安装CPU版本的PaddlePaddle"
          echo
T
tianshuo78520a 已提交
161 162 163 164 165 166 167 168 169
          use_cpu
       fi

       if [ "$GPU" == "cpu" ];then
          break
       fi
   done
}

T
tianshuo78520a 已提交
170
function checkLinuxMathLibrary(){
T
tianshuo78520a 已提交
171 172 173
  while true
    do
      if [ "$AVX" ==  "" ];then
174 175 176
        echo "正在检测您环境中是否存在AVX指令集..."
        echo
        echo "检测结果:您电脑上没有AVX指令集,目前针对无AVX指令集的环境,我们仅提供支持mkl数学库的PaddlePaddle,将为您安装此版本的PaddlePaddle"
T
tianshuo78520a 已提交
177 178 179 180
        math='mkl'
        break
      elif [ "$GPU" == "gpu" ];then
        math='mkl'
181
        echo "检测到您的机器上配备GPU,推荐您使用mkl数学库"
T
tianshuo78520a 已提交
182 183
        break
      else
184 185 186 187
        read -p "请输入您希望使用的数学库:
            1:openblas 一个高性能多核 BLAS 库
            2:mkl(推荐) 英特尔数学核心函数库
            => 请输入数字1或2。如输入其他字符或直接回车,将会默认选择【 2. mkl 】 。请在这里输入并回车:" math
T
tianshuo78520a 已提交
188 189
          if [ "$math" == "" ];then
            math="mkl"
190
            echo "您选择了数字【2】"
T
tianshuo78520a 已提交
191 192 193 194
            break
          fi
          if [ "$math" == "1" ];then
            math=openblas
195
            echo "您选择了数字【1】"
T
tianshuo78520a 已提交
196 197 198
            break
          elif [ "$math" == "2" ];then
            math=mkl
199
            echo "您选择了数字【2】"
T
tianshuo78520a 已提交
200 201 202 203 204 205 206
            break
          fi
          echo "输入错误,请再次输入"
      fi
    done
}

T
tianshuo78520a 已提交
207
function checkLinuxPaddleVersion(){
208
  read -n1 -p "请按回车键继续..."
T
tianshuo78520a 已提交
209 210
  while true
    do
211 212 213 214
      read -p "
               1. 开发版:对应Github上develop分支,如您需要开发、或希望使用PaddlePaddle最新功能,请选用此版本
               2. 稳定版(推荐):如您无特殊开发需求,建议使用此版本,目前最新的版本号为 ${release_version}
                => 请输入数字1或2。如输入其他字符或直接回车,将会默认选择【 2. 稳定版 】 。请在这里输入并回车:" paddle_version
T
tianshuo78520a 已提交
215 216
        if [ "$paddle_version" == "" ];then
          paddle_version="release-${release_version}"
217
          echo "您选择了数字【2】,为您安装release-${release_version}"
T
tianshuo78520a 已提交
218 219 220
          break
        fi
        if [ "$paddle_version" == "1" ];then
221
          echo "您选择了数字【1】,将为您安装开发版"
T
tianshuo78520a 已提交
222 223
          break
        elif [ "$paddle_version" == "2" ];then
224
          echo "您选择了数字【2】,为您安装release-${release_version}"
T
tianshuo78520a 已提交
225 226 227 228 229 230
          break
        fi
        echo "输入错误,请再次输入"
    done
}

T
tianshuo78520a 已提交
231
function checkLinuxPip(){
T
tianshuo78520a 已提交
232 233
  while true
    do
234
       echo "请输入您要使用的pip目录(您可以另起终端,并使用which pip来查看):"
T
tianshuo78520a 已提交
235 236
       read -p "" pip_path
       if [ "$pip_path" == "" -o ! -f "$pip_path" ];then
237
         echo "检测结果:pip不存在,请重新输入"
T
tianshuo78520a 已提交
238 239 240 241 242 243 244 245 246 247 248
         continue
       fi
       python_version=`$pip_path --version|awk -F "[ |)]" '{print $6}'|sed 's#\.##g'`
       if [ "$python_version" == "27" ];then
         uncode=`python -c "import pip._internal;print(pip._internal.pep425tags.get_supported())"|grep "cp27mu"`
         if [[ "$uncode" == "" ]];then
            uncode=
         else
            uncode=u
         fi
       fi
T
tianshuo78520a 已提交
249
       if [ "$python_version" == "" ];then
250
         echo "检测结果:pip不存在,请重新输入"
T
tianshuo78520a 已提交
251
       else
T
tianshuo78520a 已提交
252 253
         version_list=`echo "${python_list[@]}" | grep "$python_version" `
         if [ "$version_list" != "" ];then
254
           echo "检测结果:找到python${python_version}版本"
T
tianshuo78520a 已提交
255 256
           break
         else
257
           echo "检测结果:找不到可用的 pip, 我们只支持Python27/35/36/37及其对应的pip, 请重新输入, 或使用ctrl + c退出 "
T
tianshuo78520a 已提交
258
         fi
T
tianshuo78520a 已提交
259 260 261 262
       fi
    done
}

T
tianshuo78520a 已提交
263
function checkLinuxAVX(){
T
tianshuo78520a 已提交
264 265 266
  while true
  do
    if [[ "$AVX" != "" ]];then
T
tianshuo78520a 已提交
267
      AVX="avx"
T
tianshuo78520a 已提交
268 269 270
      break
    else
      if [ "$CUDA" == "8" -a "$CUDNN" == "7" ] || [ "$GPU" == "cpu" ];then
T
tianshuo78520a 已提交
271
        AVX="noavx"
T
tianshuo78520a 已提交
272 273
        break
      else
274 275 276
        echo "Step 6. 检测是否有avx"
        echo
        echo "检测结果:未能找到avx,我们仅提供CPU版本或配置为CUDA8 cuDNN7的GPU版本的安装包"
T
tianshuo78520a 已提交
277 278 279 280 281 282
        break
      fi
    fi
  done
}

T
tianshuo78520a 已提交
283
function PipLinuxInstall(){
T
tianshuo78520a 已提交
284 285
  wheel_cpu_release="http://paddle-wheel.bj.bcebos.com/${release_version}-${GPU}-${AVX}-${math}/paddlepaddle-${release_version}-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
  wheel_gpu_release="http://paddle-wheel.bj.bcebos.com/${release_version}-gpu-cuda${CUDA}-cudnn${CUDNN}-${AVX}-${math}/paddlepaddle_gpu-${release_version}.post${CUDA}${CUDNN}-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
T
tianshuo78520a 已提交
286
  wheel_gpu_release_noavx="http://paddle-wheel.bj.bcebos.com/${release_version}-gpu-cuda${CUDA}-cudnn${CUDNN}-${AVX}-${math}/paddlepaddle_gpu-${release_version}-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
T
tianshuo78520a 已提交
287 288 289 290 291 292 293
  wheel_cpu_develop="http://paddle-wheel.bj.bcebos.com/latest-cpu-${AVX}-${math}/paddlepaddle-latest-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
  wheel_gpu_develop="http://paddle-wheel.bj.bcebos.com/latest-gpu-cuda${CUDA}-cudnn${CUDNN}-${AVX}-${math}/paddlepaddle_gpu-latest-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"


  if [[ "$paddle_version" == "2" ]];then
    if [[ "$GPU" == "gpu" ]];then
        if [[ ${AVX} == "avx" ]];then
T
tianshuo78520a 已提交
294
          rm -rf `echo $wheel_gpu_release|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
295
          wget -q $wheel_gpu_release
296
          if [ "$?" == "0" ];then
T
tianshuo78520a 已提交
297 298
            $pip_path install --user -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_gpu_release
          else
299
            echo "paddlepaddle whl包下载失败"
T
tianshuo78520a 已提交
300 301
            exit 1
          fi
T
tianshuo78520a 已提交
302
        else
T
tianshuo78520a 已提交
303
          rm -rf `echo $wheel_gpu_release_novax|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
304
          wget -q $wheel_gpu_release_novax
305
          if [ "$?" == "0" ];then
T
tianshuo78520a 已提交
306 307
            $pip_path install --user -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_gpu_release_noavx
          else
308
            echo "paddlepaddle whl包下载失败"
T
tianshuo78520a 已提交
309 310
            exit 1
          fi
T
tianshuo78520a 已提交
311 312
        fi
    else
T
tianshuo78520a 已提交
313
        rm -rf `echo $wheel_cpu_release|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
314
        wget -q $wheel_cpu_release
315
        if [ "$?" == "0" ];then
T
tianshuo78520a 已提交
316 317
          $pip_path install --user -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_cpu_release
        else
318
          echo "paddlepaddle whl包下载失败"
T
tianshuo78520a 已提交
319 320
          exit 1
        fi
T
tianshuo78520a 已提交
321 322 323 324
    fi
  else
    if [[ "$GPU" == "gpu" ]];then
        rm -rf `echo $wheel_gpu_develop|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
325
        wget -q $wheel_gpu_develop
326
        if [ "$?" == "0" ];then
T
tianshuo78520a 已提交
327 328
          $pip_path install --user -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_gpu_develop
        else
329
          echo "paddlepaddle whl包下载失败"
T
tianshuo78520a 已提交
330 331
          exit 1
        fi
T
tianshuo78520a 已提交
332 333
    else
        rm -rf `echo $wheel_cpu_develop|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
334
        wget -q $wheel_cpu_develop
335
        if [ "$?" == "0" ];then
T
tianshuo78520a 已提交
336 337
          $pip_path install --user -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_cpu_develop
        else
338
          echo "paddlepaddle whl包下载失败"
T
tianshuo78520a 已提交
339 340
          exit 1
        fi
T
tianshuo78520a 已提交
341 342 343 344 345
    fi
  fi
}


T
tianshuo78520a 已提交
346
function checkLinuxGPU(){
347 348
  read -n1 -p "即将检测您的机器是否含GPU,请按回车键继续..."
  echo
T
tianshuo78520a 已提交
349
  AVX=`cat /proc/cpuinfo |grep avx|tail -1|grep avx`
T
tianshuo78520a 已提交
350 351
  which nvidia-smi >/dev/null 2>&1
  if [ "$?" != "0" ];then
T
tianshuo78520a 已提交
352
    GPU='cpu'
353
    echo "未在机器上找到GPU,或PaddlePaddle暂不支持此型号的GPU"
T
tianshuo78520a 已提交
354 355
  else
    GPU='gpu'
356 357
    echo "已在您的机器上找到GPU,即将确认CUDA和CUDNN版本..."
    echo
T
tianshuo78520a 已提交
358 359
  fi
  if [ "$GPU" == 'gpu' ];then
T
tianshuo78520a 已提交
360 361
    checkLinuxCUDA
    checkLinuxCUDNN
T
tianshuo78520a 已提交
362 363 364
  fi
}

365
function linux(){
T
tianshuo78520a 已提交
366 367
gpu_list=(
"GeForce 410M"
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
"GeForce 610M"
"GeForce 705M"
"GeForce 710M"
"GeForce 800M"
"GeForce 820M"
"GeForce 830M"
"GeForce 840M"
"GeForce 910M"
"GeForce 920M"
"GeForce 930M"
"GeForce 940M"
"GeForce GT 415M"
"GeForce GT 420M"
"GeForce GT 430"
"GeForce GT 435M"
"GeForce GT 440"
"GeForce GT 445M"
"GeForce GT 520"
"GeForce GT 520M"
"GeForce GT 520MX"
"GeForce GT 525M"
"GeForce GT 540M"
"GeForce GT 550M"
"GeForce GT 555M"
"GeForce GT 610"
"GeForce GT 620"
"GeForce GT 620M"
"GeForce GT 625M"
"GeForce GT 630"
"GeForce GT 630M"
"GeForce GT 635M"
"GeForce GT 640"
"GeForce GT 640 (GDDR5)"
"GeForce GT 640M"
"GeForce GT 640M LE"
"GeForce GT 645M"
"GeForce GT 650M"
"GeForce GT 705"
"GeForce GT 720"
"GeForce GT 720M"
"GeForce GT 730"
"GeForce GT 730M"
"GeForce GT 735M"
"GeForce GT 740"
"GeForce GT 740M"
"GeForce GT 745M"
"GeForce GT 750M"
"GeForce GTS 450"
"GeForce GTX 1050"
"GeForce GTX 1060"
"GeForce GTX 1070"
"GeForce GTX 1080"
"GeForce GTX 1080 Ti"
"GeForce GTX 460"
"GeForce GTX 460M"
"GeForce GTX 465"
"GeForce GTX 470"
"GeForce GTX 470M"
"GeForce GTX 480"
"GeForce GTX 480M"
"GeForce GTX 485M"
"GeForce GTX 550 Ti"
"GeForce GTX 560M"
"GeForce GTX 560 Ti"
"GeForce GTX 570"
"GeForce GTX 570M"
"GeForce GTX 580"
"GeForce GTX 580M"
"GeForce GTX 590"
"GeForce GTX 650"
"GeForce GTX 650 Ti"
"GeForce GTX 650 Ti BOOST"
"GeForce GTX 660"
"GeForce GTX 660M"
"GeForce GTX 660 Ti"
"GeForce GTX 670"
"GeForce GTX 670M"
"GeForce GTX 670MX"
"GeForce GTX 675M"
"GeForce GTX 675MX"
"GeForce GTX 680"
"GeForce GTX 680M"
"GeForce GTX 680MX"
"GeForce GTX 690"
"GeForce GTX 750"
"GeForce GTX 750 Ti"
"GeForce GTX 760"
"GeForce GTX 760M"
"GeForce GTX 765M"
"GeForce GTX 770"
"GeForce GTX 770M"
"GeForce GTX 780"
"GeForce GTX 780M"
"GeForce GTX 780 Ti"
"GeForce GTX 850M"
"GeForce GTX 860M"
"GeForce GTX 870M"
"GeForce GTX 880M"
"GeForce GTX 950"
"GeForce GTX 950M"
"GeForce GTX 960"
"GeForce GTX 960M"
"GeForce GTX 965M"
"GeForce GTX 970"
"GeForce GTX 970M"
"GeForce GTX 980"
"GeForce GTX 980M"
"GeForce GTX 980 Ti"
"GeForce GTX TITAN"
"GeForce GTX TITAN Black"
"GeForce GTX TITAN X"
"GeForce GTX TITAN Z"
"Jetson TK1"
"Jetson TX1"
"Jetson TX2"
"Mobile Products"
"NVIDIA NVS 310"
"NVIDIA NVS 315"
"NVIDIA NVS 510"
"NVIDIA NVS 810"
"NVIDIA TITAN V"
"NVIDIA TITAN X"
"NVIDIA TITAN Xp"
"NVS 4200M"
"NVS 5200M"
"NVS 5400M"
"Quadro 410"
"Quadro GP100"
"Quadro K1100M"
"Quadro K1200"
"Quadro K2000"
"Quadro K2000D"
"Quadro K2100M"
"Quadro K2200"
"Quadro K2200M"
"Quadro K3100M"
"Quadro K4000"
"Quadro K4100M"
"Quadro K420"
"Quadro K4200"
"Quadro K4200M"
"Quadro K5000"
"Quadro K500M"
"Quadro K5100M"
"Quadro K510M"
"Quadro K5200"
"Quadro K5200M"
"Quadro K600"
"Quadro K6000"
"Quadro K6000M"
"Quadro K610M"
"Quadro K620"
"Quadro K620M"
"Quadro M1000M"
"Quadro M1200"
"Quadro M2000"
"Quadro M2000M"
"Quadro M2200"
"Quadro M3000M"
"Quadro M4000"
"Quadro M4000M"
"Quadro M5000"
"Quadro M5000M"
"Quadro M500M"
"Quadro M520"
"Quadro M5500M"
"Quadro M6000"
"Quadro M6000 24GB"
"Quadro M600M"
"Quadro M620"
"Quadro Mobile Products"
"Quadro P1000"
"Quadro P2000"
"Quadro P3000"
"Quadro P400"
"Quadro P4000"
"Quadro P5000"
"Quadro P600"
"Quadro P6000"
"Quadro Plex 7000"
"Tegra K1"
"Tegra X1"
"Tesla C2050/C2070"
"Tesla C2075"
"Tesla Data Center Products"
"Tesla K10"
"Tesla K20"
"Tesla K40"
"Tesla K80"
"Tesla M40"
"Tesla M60"
"Tesla P100"
"Tesla P4"
"Tesla P40"
"Tesla V100")
563 564 565

  echo "Step 2. 检测GPU型号和CUDA/cuDNN版本"
  echo
T
tianshuo78520a 已提交
566
  checkLinuxGPU
567 568 569
  echo
  echo "Step 3. 检测数学库"
  echo
T
tianshuo78520a 已提交
570
  checkLinuxMathLibrary
571 572 573
  echo
  echo "Step 4. 选择要安装的PaddlePaddle版本"
  echo
T
tianshuo78520a 已提交
574
  checkLinuxPaddleVersion
575 576 577
  echo
  echo "Step 5. 检测pip版本"
  echo
T
tianshuo78520a 已提交
578
  checkLinuxPip
579
  echo
T
tianshuo78520a 已提交
580
  checkLinuxAVX
581
  echo "*********************2. 开始安装*****************************"
T
tianshuo78520a 已提交
582
  PipLinuxInstall
583
}
T
tianshuo78520a 已提交
584

585 586 587 588 589 590 591 592 593 594 595 596 597
function checkMacPython2(){
    while true
       do
          read -p "
                => 未能在常规路径下找到Python2,请使用ctrl+c命令退出安装程序,并使用brew或pypi.org下载安装Python2(注意Python版本不能低于2.7.15)
                如希望自定义Python路径,请输入路径:" python_root
          echo
          python_version=`$python_root --version 2>&1 1>&1`
          if [ $? == "0" ];then
            :
          else
            python_version=""
          fi
S
shanyi15 已提交
598
          check_python=`echo $python_version | grep "Python 2"`
599 600
          if [ "$python_version" == "" ] || [ "$python_root" == "/usr/bin/python" -a "$python_version" == "Python 2.7.10" ]  ;then
               python_version=""
S
shanyi15 已提交
601
          elif [ -n "$check_python" ];then
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
              while true
                do
                  read -p "
                => 在您的环境中找到 $python_version, 确认使用此版本请输入y;如您希望自定义Python路径请输入n。请在这里输入(y/n)并回车: " use_python
                  echo
                  use_python=`echo $use_python | tr 'A-Z' 'a-z'`
                  if [ "$use_python" == "y" ]||[ "$use_python" == "" ];then
                       use_python="y"
                       break
                  elif [ "$use_python" == "n" ];then
                       python_root=""
                       break
                  else
                      echo "输入错误,请重新输入(y/n)"
                  fi
                done
              if [ "$use_python" == "y" ];then
                break
              fi
S
shanyi15 已提交
621 622 623 624
            else
              echo "您输入Python的不是Python2"
              python_version=""
            fi
625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
       done
}

function checkMacPython3(){
    while true
       do
          read -p "
                => 未能在常规路径下找到Python3,请使用ctrl+c命令退出安装程序,并使用brew或pypi.org下载Python3
                如希望自定义Python路径,请输入路径:" python_root
          python_version=`$python_root --version  2>&1 1>&1`
          if [ $? == "0" ];then
              :
          else
              python_version=""
          fi
S
shanyi15 已提交
640
          check_python=`echo $python_version | grep "Python 3"`
641 642
          if [ "$python_version" == "" ] || [ "$python_root" == "/usr/bin/python" -a "$python_version" == "Python 2.7.10" ] ;then
               python_version=""
S
shanyi15 已提交
643
          elif [ -n "$check_python" ] ;then
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
              while true
                do
                  read -p "
                => 在您的环境中找到 $python_version, 确认使用此版本请输入y;如您希望自定义Python路径请输入n。请在这里输入(y/n)并回车: " use_python
                  echo
                  use_python=`echo $use_python | tr 'A-Z' 'a-z'`
                  if [ "$use_python" == "y" ]||[ "$use_python" == "" ];then
                       use_python="y"
                       break
                  elif [ "$use_python" == "n" ];then
                        python_root=""
                        break
                  else
                      echo "输入错误,请重新输入(y/n)"
                  fi
                done
              if [ "$use_python" == "y" ];then
                    break
              fi
S
shanyi15 已提交
663 664 665 666
            else
              echo "您输入Python的不是Python3"
              python_version=""
            fi
667 668 669
       done
}

J
JiabinYang 已提交
670
function checkMacPaddleVersion(){
671
  while true
J
JiabinYang 已提交
672
    do
673 674 675 676 677 678 679
      read -n1 -p "Step 2. 选择PaddlePaddle的版本,请按回车键继续..."
      echo
      read -p "
               1. 开发版:对应Github上develop分支,如您需要开发、或希望使用PaddlePaddle最新功能,请选用此版本
               2. 稳定版(推荐):如您无特殊开发需求,建议使用此版本,目前最新的版本号为 ${release_version}

               => 请输入数字1或2。如输入其他字符或直接回车,将会默认选择【 2. 稳定版 】 。请在这里输入并回车:" paddle_version
J
JiabinYang 已提交
680
      if [ "$paddle_version" == "1" ]||[ "$paddle_version" == "2" ];then
681 682 683
          echo
          echo "您选择了数字【"$paddle_version" 】"
          echo
J
JiabinYang 已提交
684 685 686
          break
      else
          paddle_version="2"
687 688 689
          echo
          echo "您选择了数字【2】"
          echo
J
JiabinYang 已提交
690 691 692 693
          break
      fi
    done
}
694

J
JiabinYang 已提交
695 696 697
function checkMacPythonVersion(){
  while true
    do
698 699 700 701 702 703 704
       read -n1 -p "Step 3. 选择Python版本,请按回车键继续..."
       read -p "
               2. 使用python 2.x
               3. 使用python 3.x

                => 请输入数字2或3。如输入其他字符或直接回车,将会默认使用【Python 2 】。请在这里输入并回车:" python_V
                echo
J
JiabinYang 已提交
705 706 707
       if [ "$python_V" == "" ];then
            python_V="2"
       fi
S
shanyi15 已提交
708
       echo "您选择了数字【"$python_V"】,正在寻找符合您要求的Python版本,请按回车键继续..."
709
       echo
J
JiabinYang 已提交
710 711 712 713
       if [ "$python_V" == "2" ];then
           python_root=`which python2.7`
           if [ "$python_root" == "" ];then
                python_root=`which python`
714
           fi
J
JiabinYang 已提交
715 716 717 718 719 720 721
           python_version=`$python_root --version 2>&1 1>&1`
           if [ $? == "0" ];then
               :
           else
               python_version=""
           fi
           if [ "$python_root" == "" ]||[ "$python_root" == "/usr/bin/python" -a "$python_version" == "Python 2.7.10" ]||[ "$python_root" == "/usr/bin/python2.7" -a "$python_version" == "Python 2.7.10" ];then
T
tianshuo78520a 已提交
722
               checkMacPython2
J
JiabinYang 已提交
723 724 725
           fi
           while true
             do
726 727 728
               read -p "
                => 在您的环境中找到 $python_version, 确认使用此版本请输入y;如您希望自定义Python路径请输入n。请在这里输入(y/n)并回车:" use_python
               echo
J
JiabinYang 已提交
729 730 731 732 733
               use_python=`echo $use_python | tr 'A-Z' 'a-z'`
               if [ "$use_python" == "y" ]||[ "$use_python" == "" ];then
                    break
               elif [ "$use_python" == "n" ];then
                    python_root=""
T
tianshuo78520a 已提交
734
                    checkMacPython2
J
JiabinYang 已提交
735
                    break
736
               else
737
                    echo "输入错误,请重新输入(y/n)"
738
               fi
J
JiabinYang 已提交
739
            done
740

J
JiabinYang 已提交
741 742 743 744
       elif [ "$python_V" == "3" ];then
           python_root=`which python3`
           python_version=`$python_root --version 2>&1 1>&1`
           if [ $? == "0" ];then
745
               :
J
JiabinYang 已提交
746 747
           else
               python_version=""
748
           fi
J
JiabinYang 已提交
749
           if [ "$python_root" == "" ]||[ "$python_root" == "/usr/bin/python" -a "$python_version" == "Python 2.7.10" ];then
T
tianshuo78520a 已提交
750
               checkMacPython3
J
JiabinYang 已提交
751 752 753
           fi
           while true
             do
754 755 756
               read -p "
                => 在您的环境中找到 $python_version, 确认使用此版本请输入y;如您希望自定义Python路径请输入n。请在这里输入(y/n)并回车:" use_python
               echo
J
JiabinYang 已提交
757 758 759 760
               use_python=`echo $use_python | tr 'A-Z' 'a-z'`
               if [ "$use_python" == "y" ]||[ "$use_python" == "" ];then
                   break
               elif [ "$use_python" == "n" ];then
T
tianshuo78520a 已提交
761
                    checkMacPython3
762 763
                    break
               else
764
                    echo "输入错误,请重新输入(y/n)"
765
               fi
J
JiabinYang 已提交
766 767 768 769 770
           done
       else
           :
       fi

771

J
JiabinYang 已提交
772 773 774 775 776
       if [ "$python_V" == "2" ]||[ "$python_V" == "3" ];then
           python_brief_version=`$python_root -m pip -V |awk -F "[ |)]" '{print $6}'|sed 's#\.##g'`
           if [[ $python_brief_version == "27" ]];then
              uncode=`python -c "import pip._internal;print(pip._internal.pep425tags.get_supported())"|grep "cp27"`
              if [[ $uncode == "" ]];then
T
tianshuo78520a 已提交
777
                 uncode="mu"
J
JiabinYang 已提交
778
              else
T
tianshuo78520a 已提交
779
                 uncode="m"
J
JiabinYang 已提交
780 781
              fi
           fi
T
tianshuo78520a 已提交
782
           version_list=`echo "${python_list[@]}" | grep "$python_brief_version" `
T
tianshuo78520a 已提交
783 784 785
           if [ "$version_list" != "" ];then
              break
            else
786
              echo "未找到可用的pip或pip3。PaddlePaddle目前支持:Python2.7/3.5/3.6/3.7及其对应的pip, 请重新输入,或使用ctrl + c退出"
T
tianshuo78520a 已提交
787
           fi
J
JiabinYang 已提交
788 789 790 791 792
        else
            echo "输入错误,请重新输入"
        fi
  done
}
793

J
JiabinYang 已提交
794
function checkMacAVX(){
795 796
    read -n1 -p "Step 4. 检测您的Mac是否支持AVX指令集,请按回车键继续..."
    echo
J
JiabinYang 已提交
797
    if [[ $AVX != "" ]];then
T
tianshuo78520a 已提交
798
        AVX="avx"
799
        echo "检测结果:支持"
J
JiabinYang 已提交
800
    else
J
JiabinYang 已提交
801 802
        read -n1 -p "检测结果:不支持。非常抱歉,PaddlePaddle在Mac系统暂不提供no_avx类型的安装包,您可以选择在Linux系统中安装no_avx版的PaddlePaddle, 请按回车键退出..."
        exit(0)
J
JiabinYang 已提交
803
    fi
804
    echo
J
JiabinYang 已提交
805
}
806

J
JiabinYang 已提交
807
function checkMacGPU(){
808 809
    read -n1 -p "Step 5. 选择CPU/GPU版本,请按回车键继续..."
    echo
J
JiabinYang 已提交
810
    if [[ $GPU != "" ]];then
811
        echo "MacOS环境下,暂未提供GPU版本的PaddlePaddle安装包,将为您安装CPU版本的PaddlePaddle"
J
JiabinYang 已提交
812
    else
813
        echo "MacOS环境下,暂未提供GPU版本的PaddlePaddle安装包,将为您安装CPU版本的PaddlePaddle"
814
        GPU=cpu
J
JiabinYang 已提交
815
    fi
816
    echo
J
JiabinYang 已提交
817
}
818

J
JiabinYang 已提交
819 820 821 822 823 824 825 826 827 828
function macos() {
  path='http://paddlepaddle.org/download?url='
  AVX=`sysctl -a | grep cpu | grep AVX1.0 | tail -1 | grep AVX`

  while true
      do
        checkMacPaddleVersion
        checkMacPythonVersion
        checkMacAVX
        checkMacGPU
829 830


831 832 833 834
        echo "*********************2. 开始安装*****************************"
        echo
        read -n1 -p "即将为您下载并安装PaddlePaddle,请按回车键继续..."
        echo
J
JiabinYang 已提交
835
        if [[ $paddle_version == "2" ]];then
J
JiabinYang 已提交
836 837 838 839
            $python_root -m pip install paddlepaddle
            if [ $? == "0" ];then
               echo "安装成功,可以使用: ${python_root} 来启动安装了PaddlePaddle的Python解释器"
               break
840
            else
J
JiabinYang 已提交
841 842 843 844 845 846
               rm  $whl_cpu_release
               echo "未能正常安装PaddlePaddle,请尝试更换您输入的python路径,或者ctrl + c退出后请检查您使用的python对应的pip或pip源是否可用"
               echo""
               echo "=========================================================================================="
               echo""
               exit 1
847
            fi
J
JiabinYang 已提交
848
        else
849 850 851 852
            if [ -f $whl_cpu_develop ];then
                $python_root -m pip install $whl_cpu_develop
                if [ $? == "0" ];then
                   rm -rf $whl_cpu_develop
853
                   echo "安装成功!小提示:可以使用: ${python_root} 来启动安装了PaddlePaddle的Python解释器"
854 855
                   break
                else
J
JiabinYang 已提交
856
                   echo "未能正常安装PaddlePaddle,请尝试更换您输入的python路径,或者ctrl + c退出后请检查您使用的python对应的pip或pip源是否可用"
857 858 859
                   echo""
                   echo "=========================================================================================="
                   echo""
T
tianshuo78520a 已提交
860
                   exit 1
861 862 863 864 865 866
                fi
            else
                wget ${path}$whl_cpu_develop -O $whl_cpu_develop
                if [ $? == "0" ];then
                    $python_root -m pip install $whl_cpu_develop
                    if [ $? == "0" ];then
J
JiabinYang 已提交
867
                       rm  $wheel_cpu_develop
868 869 870
                       echo "安装成功,可以使用: ${python_root} 来启动安装了PaddlePaddle的Python解释器"
                       break
                    else
J
JiabinYang 已提交
871
                       rm  $whl_cpu_release
J
JiabinYang 已提交
872
                       echo "未能正常安装PaddlePaddle,请尝试更换您输入的python路径,或者ctrl + c退出后请检查您使用的python对应的pip或pip源是否可用"
873 874 875
                       echo""
                       echo "=========================================================================================="
                       echo""
T
tianshuo78520a 已提交
876
                       exit 1
877 878
                    fi
                else
J
JiabinYang 已提交
879
                      rm  $whl_cpu_develop
J
JiabinYang 已提交
880
                      echo "未能正常安装PaddlePaddle,请检查您的网络 或者确认您是否安装有 wget,或者ctrl + c退出后反馈至https://github.com/PaddlePaddle/Paddle/issues"
881 882 883
                      echo""
                      echo "=========================================================================================="
                      echo""
T
tianshuo78520a 已提交
884
                      exit 1
885 886
                fi
            fi
J
JiabinYang 已提交
887
        fi
888 889 890 891
  done
}

function main() {
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906
  echo "*********************************"
  echo "欢迎使用PaddlePaddle快速安装脚本"
  echo "*********************************"
  echo
  echo "如果您在安装过程中遇到任何问题,请在https://github.com/PaddlePaddle/Paddle/issues反馈,我们的工作人员将会帮您答疑解惑"
  echo
  echo "本安装包将帮助您在Linux或Mac系统下安装PaddlePaddle,包括 1)安装前的准备和 2)开始安装 两部分"
  echo
  read -n1 -p "请按回车键进行下一步..."
  echo
  echo
  echo "*********************1. 安装前的准备*****************************"
  echo
  echo "Step 1. 正在检测您的操作系统信息..."
  echo
907 908
  SYSTEM=`uname -s`
  if [ "$SYSTEM" == "Darwin" ];then
909 910
  	echo "您的系统为:MAC OSX"
    echo
911 912
  	macos
  else
913 914
 	echo "您的系统为:Linux"
  echo
915 916 917
	  OS=`cat /etc/issue|awk 'NR==1 {print $1}'`
	  if [ $OS == "\S" ] || [ "$OS" == "CentOS" ] || [ $OS == "Ubuntu" ];then
	    linux
918 919
	  else
	    echo "您的系统不在本安装包的支持范围,如您需要在windows环境下安装PaddlePaddle,请您参考PaddlePaddle官网的windows安装文档"
920 921 922 923
	  fi
  fi
}
main