fast_install.sh 34.5 KB
Newer Older
1 2
#!/bin/bash

S
seemingwang 已提交
3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

J
Jiabin Yang 已提交
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
## purple to echo
function purple(){
    echo -e "\033[35m$1\033[0m"
}


## green to echo
function green(){
    echo -e "\033[32m$1\033[0m"
}

## Error to warning with blink
function bred(){
    echo -e "\033[31m\033[01m\033[05m$1\033[0m"
}

## Error to warning with blink
function byellow(){
    echo -e "\033[33m\033[01m\033[05m$1\033[0m"
}


## Error
function red(){
    echo -e "\033[31m\033[01m$1\033[0m"
}

## warning
function yellow(){
    echo -e "\033[33m\033[01m$1\033[0m"
}

49
path='http://paddlepaddle.org/download?url='
50
release_version=`curl -s https://pypi.org/project/paddlepaddle/|grep -E "/project/paddlepaddle/"|grep "release"|awk -F '/' '{print $(NF-1)}'|head -1`
T
tianshuo78520a 已提交
51 52 53 54 55 56 57
python_list=(
"27"
"35"
"36"
"37"
)

58 59 60 61

function use_cpu(){
   while true
    do
62
     read -p "是否安装CPU版本的PaddlePaddle?(y/n)" cpu_option
63
     cpu_option=`echo $cpu_option | tr 'A-Z' 'a-z'`
T
tianshuo78520a 已提交
64
     if [[ "$cpu_option" == "" || "$cpu_option" == "n" ]];then
65
        echo "退出安装中..."
66 67 68
        exit
     else
        GPU='cpu'
69
        echo "将为您安装CPU版本的PaddlePaddle"
70 71 72 73 74
        break
     fi
    done
}

T
tianshuo78520a 已提交
75
function checkLinuxCUDNN(){
76 77 78
   echo
   read -n1 -p "请按回车键进行下一步..."
   echo
T
tianshuo78520a 已提交
79 80 81 82 83 84 85 86 87 88 89
   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
90
               echo "检测结果:未在常规路径下找到cuda/include/cudnn.h文件"
T
tianshuo78520a 已提交
91 92
               while true
               do
93 94
                  read -p "请核实cudnn.h位置,并在此输入路径(请注意,路径需要输入到“cudnn.h”这一级):" cudnn_version
                  echo
T
tianshuo78520a 已提交
95
                  if [ "$cudnn_version" == "" ] || [ ! -f "$cudnn_version" ];then
96 97
                        read -p "仍未找到cuDNN,输入y将安装CPU版本的PaddlePaddle,输入n可重新录入cuDNN路径,请输入(y/n)" cpu_option
                        echo
T
tianshuo78520a 已提交
98 99 100 101 102
                        cpu_option=`echo $cpu_option | tr 'A-Z' 'a-z'`
                        if [ "$cpu_option" == "y" -o "$cpu_option" == "" ];then
                            GPU='cpu'
                            break
                        else
103 104
                            echo "请重新输入"
                            echo
T
tianshuo78520a 已提交
105 106 107
                        fi
                  else
                     CUDNN=`cat $cudnn_version | grep CUDNN_MAJOR |awk 'NR==1{print $NF}'`
108
                     echo "检测结果:找到cudnn.h"
T
tianshuo78520a 已提交
109 110 111 112 113 114 115 116 117
                     break
                  fi
                 done
             if [ "$GPU" == "cpu" ];then
                break
             fi
           fi
       fi
       if [ "$CUDA" == "9" -a "$CUDNN" != "7" ];then
118 119 120
           echo
           echo "目前CUDA9下仅支持cuDNN7,暂不支持您机器上的CUDNN${CUDNN}。您可以访问NVIDIA官网下载适合版本的CUDNN,请ctrl+c退出安装进程。按回车键将为您安装CPU版本的PaddlePaddle"
           echo
T
tianshuo78520a 已提交
121 122 123 124 125 126 127
          use_cpu()
          if [ "$GPU"=="cpu" ];then
             break
          fi
       fi

       if [ "$CUDNN" == 5 ] || [ "$CUDNN" == 7 ];then
128 129
          echo
          echo "您的CUDNN版本是: CUDNN$CUDNN"
T
tianshuo78520a 已提交
130 131
          break
       else
132 133 134
          echo
          read -n1 -p "目前支持的CUDNN版本为5和7,暂不支持您机器上的CUDNN${CUDNN},将为您安装CPU版本的PaddlePaddle,请按回车键开始安装"
          echo
T
tianshuo78520a 已提交
135 136 137 138 139 140 141 142
          use_cpu
          if [ "$GPU"=="cpu" ];then
             break
          fi
       fi
   done
}

T
tianshuo78520a 已提交
143
function checkLinuxCUDA(){
T
tianshuo78520a 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
   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
160 161 162 163
         if [ -f "/usr/local/cuda10/version.txt" ];then
           CUDA=`cat /usr/local/cuda10/version.txt | grep 'CUDA Version'|awk -F '[ .]' '{print $3}'`
           tmp_cuda10=$CUDA
         fi
T
tianshuo78520a 已提交
164 165 166
       fi

       if [ "$tmp_cuda" != "" ];then
167
         echo "检测结果:找到CUDA $tmp_cuda"
T
tianshuo78520a 已提交
168 169
       fi
       if [ "$tmp_cudai8" != "" ];then
170
         echo "检测结果:找到CUDA $tmp_cuda8"
T
tianshuo78520a 已提交
171 172
       fi
       if [ "$tmp_cuda9" != "" ];then
173
         echo "检测结果:找到CUDA $tmp_cuda9"
T
tianshuo78520a 已提交
174
       fi
175 176 177
       if [ "$tmp_cuda10" != "" ];then
         echo "检测结果:找到CUDA $tmp_cuda10"
       fi
T
tianshuo78520a 已提交
178 179

       if [ "$CUDA" == "" ];then
180
            echo "检测结果:没有在常规路径下找到cuda/version.txt文件"
T
tianshuo78520a 已提交
181 182
            while true
            do
183
                read -p "请输入cuda/version.txt的路径:" cuda_version
T
tianshuo78520a 已提交
184
                if [ "$cuda_version" == "" || ! -f "$cuda_version" ];then
185
                    read -p "仍未找到CUDA,输入y将安装CPU版本的PaddlePaddle,输入n可重新录入CUDA路径,请输入(y/n)" cpu_option
T
tianshuo78520a 已提交
186 187 188 189 190 191 192 193 194 195
                    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
196
                        echo "未能在version.txt中找到CUDA相关信息"
T
tianshuo78520a 已提交
197 198 199 200 201 202 203 204 205 206
                    else
                        break
                    fi
                fi
            done
            if [ "$GPU" == "cpu" ];then
                break
            fi
       fi

207
       if [ "$CUDA" == "8" ] || [ "$CUDA" == "9" ] || [ "$CUDA" == "10" ];then
T
tianshuo78520a 已提交
208 209 210
          echo "您的CUDA版本是${CUDA}"
          break
       else
211
          echo "目前支持CUDA8/9/10,暂不支持您的CUDA${CUDA},将为您安装CPU版本的PaddlePaddle"
212
          echo
T
tianshuo78520a 已提交
213 214 215 216 217 218 219 220 221
          use_cpu
       fi

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

T
tianshuo78520a 已提交
222
function checkLinuxMathLibrary(){
T
tianshuo78520a 已提交
223 224
  while true
    do
225
      if [ "$GPU" == "gpu" ];then
T
tianshuo78520a 已提交
226
        math='mkl'
227
        echo "检测到您的机器上配备GPU,推荐您使用mkl数学库"
T
tianshuo78520a 已提交
228 229
        break
      else
230 231 232 233
        read -p "请输入您希望使用的数学库:
            1:openblas 一个高性能多核 BLAS 库
            2:mkl(推荐) 英特尔数学核心函数库
            => 请输入数字1或2。如输入其他字符或直接回车,将会默认选择【 2. mkl 】 。请在这里输入并回车:" math
T
tianshuo78520a 已提交
234 235
          if [ "$math" == "" ];then
            math="mkl"
236
            echo "您选择了数字【2】"
T
tianshuo78520a 已提交
237 238 239 240
            break
          fi
          if [ "$math" == "1" ];then
            math=openblas
241
            echo "您选择了数字【1】"
T
tianshuo78520a 已提交
242 243 244
            break
          elif [ "$math" == "2" ];then
            math=mkl
245
            echo "您选择了数字【2】"
T
tianshuo78520a 已提交
246 247 248 249 250 251 252
            break
          fi
          echo "输入错误,请再次输入"
      fi
    done
}

T
tianshuo78520a 已提交
253
function checkLinuxPaddleVersion(){
254
  read -n1 -p "请按回车键继续..."
T
tianshuo78520a 已提交
255 256
  while true
    do
257 258 259 260
      read -p "
               1. 开发版:对应Github上develop分支,如您需要开发、或希望使用PaddlePaddle最新功能,请选用此版本
               2. 稳定版(推荐):如您无特殊开发需求,建议使用此版本,目前最新的版本号为 ${release_version}
                => 请输入数字1或2。如输入其他字符或直接回车,将会默认选择【 2. 稳定版 】 。请在这里输入并回车:" paddle_version
T
tianshuo78520a 已提交
261
        if [ "$paddle_version" == "" ];then
262
          paddle_version="2"
263
          echo "您选择了数字【2】,为您安装release-${release_version}"
T
tianshuo78520a 已提交
264 265 266
          break
        fi
        if [ "$paddle_version" == "1" ];then
267
          echo "您选择了数字【1】,将为您安装开发版"
T
tianshuo78520a 已提交
268 269
          break
        elif [ "$paddle_version" == "2" ];then
270
          echo "您选择了数字【2】,为您安装release-${release_version}"
T
tianshuo78520a 已提交
271 272 273 274 275 276
          break
        fi
        echo "输入错误,请再次输入"
    done
}

J
Jiabin Yang 已提交
277
function checkPythonVirtualenv(){
T
tianshuo78520a 已提交
278 279
  while true
    do
J
Jiabin Yang 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338
      read -p "
                是否使用python  virtualenv虚环境安装(y/n)": check_virtualenv
    case $check_virtualenv in
      y)
        echo "为您使用python虚环境安装"
        ;;
      n)
        break
        ;;
      *)
        continue
        ;;
    esac

    virtualenv_path=`which virtualenv 2>&1`
    if [ "$virtualenv_path" == "" ];then
      $python_path -m pip install virtualenv
      if [ "$?" != '0' ];then
        echo "安装虚拟环境失败,请检查本地环境"
      fi
    fi

    while true
      do
        read -p "请输入虚拟环境名字:" virtualenv_name
        if [ "$virtualenv_name" == "" ];then
          echo "不能为空"
          continue
        fi
        break
    done

    virtualenv -p $python_path ${virtualenv_name}
    if [ "$?" != 0 ];then
      echo "创建虚环境失败,请检查环境"
      exit 2
    fi
    cd ${virtualenv_name}
    source ./bin/activate

    if [ "$?" == 0 ];then
      use_virtualenv=
      python_path=`which python`
      break
    else
      echo "创建虚环境失败,请检查环境"
      exit 2
    fi
  done
}

function checkLinuxPython(){
  python_path=`which python 2>/dev/null`
  while true
    do
  if [ "$python_path" == '' ];then
    while true
      do
        read -p "没有找到默认的python版本,请输入要安装的python路径:"  python_path
339
        python_path=`$python_path -V 2>&1` #add 2>&1
J
Jiabin Yang 已提交
340 341 342 343 344
        if [ "$python_path" != "" ];then
          break
        else
          echo "输入路径有误,未找到pyrhon"
        fi
T
tianshuo78520a 已提交
345
    done
J
Jiabin Yang 已提交
346 347 348 349 350 351 352 353 354 355 356
  fi

  python_version=`$python_path -V 2>&1|awk -F '[ .]' '{print $2$3}'`
  pip_version=`$python_path -m pip -V|awk -F '[ .]' '{print $2}'`
  while true
    do
      read -p "
                找到python版本$python_version,使用请输入y,选择其他版本请输n(y/n):"  check_python
      case $check_python in
        n)
          read -p "请指定您的python路径:" new_python_path
357
          python_V=`$new_python_path -V 2>&1` # 2>/dev/null --> 2>&1
J
Jiabin Yang 已提交
358 359
          if [ "$python_V" != "" ];then
            python_path=$new_python_path
360 361 362
            python_version=`$python_path -V 2>&1|awk -F '[ .]' 'NR==1{print $2$3}'`
            echo $python_path
            pip_version=`$python_path -m pip -V|awk -F '[ .]' 'NR==1{print $2}'`
J
Jiabin Yang 已提交
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
            echo "您的python版本为${python_version}"
            break
          else
            echo 输入有误,未找到python路径
          fi
          ;;
        y)
          break
          ;;
        *)
          echo "输入有误,请重新输入."
          continue
          ;;
      esac
  done

379
  if [ "$pip_version" -lt 10 ];then
J
Jiabin Yang 已提交
380 381 382 383
    echo "您的pip版本小于9.0.1  请升级pip (pip install --upgrade pip)"
    exit 0
  fi

384

J
Jiabin Yang 已提交
385
  if [ "$python_version" == "27" ];then
386 387 388 389 390
     python_version_all=`$python_path -V 2>&1|awk -F '[ .]' '{print $4}'`
     if [[ $python_version_all -le 15 ]];then
        echo "Python2版本小于2.7.15,请更新Python2版本或使用Python3"
        exit 0
      fi
391
     uncode=`$python_path -c "import pip._internal;print(pip._internal.pep425tags.get_supported())"|grep "cp27mu"`
J
Jiabin Yang 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405
     if [[ "$uncode" == "" ]];then
        uncode=
     else
        uncode=u
     fi
  fi

  version_list=`echo "${python_list[@]}" | grep "$python_version" `
  if [ "$version_list" == "" ];then
    echo "找不到可用的 pip, 我们只支持Python27/35/36/37及其对应的pip, 请重新输入, 或使用ctrl + c退出 "
  else
    break
  fi
  done
T
tianshuo78520a 已提交
406 407 408
}


T
tianshuo78520a 已提交
409
function PipLinuxInstall(){
410 411
  wheel_cpu_release="http://paddle-wheel.bj.bcebos.com/${release_version}-${GPU}-${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}-${math}/paddlepaddle_gpu-${release_version}.post${CUDA}${CUDNN}-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
412 413
  wheel_cpu_develop="http://paddle-wheel.bj.bcebos.com/0.0.0-cpu-${math}/paddlepaddle-0.0.0-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
  wheel_gpu_develop="http://paddle-wheel.bj.bcebos.com/0.0.0-gpu-cuda${CUDA}-cudnn${CUDNN}-${math}/paddlepaddle_gpu-0.0.0-cp${python_version}-cp${python_version}m${uncode}-linux_x86_64.whl"
414

T
tianshuo78520a 已提交
415 416 417

  if [[ "$paddle_version" == "2" ]];then
    if [[ "$GPU" == "gpu" ]];then
418
          rm -rf `echo $wheel_cpu_release|awk -F '/' '{print $NF}'`
419
          echo $wheel_gpu_release
T
tianshuo78520a 已提交
420
          wget -q $wheel_gpu_release
421
          if [ "$?" == "0" ];then
422
            $python_path -m pip install -U ${use_virtualenv} -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_gpu_release
J
Jiabin Yang 已提交
423 424
            if [ "$?" == 0 ];then
              echo 安装成功
425
              exit 0
J
Jiabin Yang 已提交
426 427 428 429
            else
              echo 安装失败
              exit 1
            fi
T
tianshuo78520a 已提交
430
          else
J
Jiabin Yang 已提交
431
            echo paddlepaddle whl包下载失败
432
            echo "wget err: $wheel_gpu_release"
T
tianshuo78520a 已提交
433 434
            exit 1
          fi
T
tianshuo78520a 已提交
435
    else
436
        echo $wheel_cpu_release
T
tianshuo78520a 已提交
437
        rm -rf `echo $wheel_cpu_release|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
438
        wget -q $wheel_cpu_release
439
        if [ "$?" == "0" ];then
440
          $python_path -m pip install -U ${use_virtualenv} -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_cpu_release
J
Jiabin Yang 已提交
441 442
          if [ "$?" == 0 ];then
              echo 安装成功
443
              exit 0
J
Jiabin Yang 已提交
444 445 446 447
            else
              echo 安装失败
              exit 1
            fi
T
tianshuo78520a 已提交
448
        else
J
Jiabin Yang 已提交
449
          echo paddlepaddle whl包下载失败
450
          echo "wget err: $wheel_cpu_release"
T
tianshuo78520a 已提交
451 452
          exit 1
        fi
T
tianshuo78520a 已提交
453
    fi
454 455
  fi
  if [[ "$GPU" == "gpu" ]];then
456
        echo $wheel_gpu_develop
T
tianshuo78520a 已提交
457
        rm -rf `echo $wheel_gpu_develop|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
458
        wget -q $wheel_gpu_develop
459
        if [ "$?" == "0" ];then
460 461
          echo $python_path,111
          $python_path -m pip install -U ${use_virtualenv} -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_gpu_develop
J
Jiabin Yang 已提交
462 463
          if [ "$?" == 0 ];then
              echo 安装成功
464
              exit 0
J
Jiabin Yang 已提交
465 466 467 468
            else
              echo 安装失败
              exit 1
            fi
T
tianshuo78520a 已提交
469
        else
J
Jiabin Yang 已提交
470
          echo paddlepaddle whl包下载失败
471
          echo "wget err: $wheel_gpu_develop" 
T
tianshuo78520a 已提交
472 473
          exit 1
        fi
474
  else
475
        echo $wheel_cpu_develop
T
tianshuo78520a 已提交
476
        rm -rf `echo $wheel_cpu_develop|awk -F '/' '{print $NF}'`
T
tianshuo78520a 已提交
477
        wget -q $wheel_cpu_develop
478
        if [ "$?" == "0" ];then
479
          $python_path -m pip install -U ${use_virtualenv} -i https://mirrors.aliyun.com/pypi/simple --trusted-host=mirrors.aliyun.com $wheel_cpu_develop
J
Jiabin Yang 已提交
480 481
          if [ "$?" == 0 ];then
              echo 安装成功
482
              exit 0
J
Jiabin Yang 已提交
483 484 485 486
            else
              echo 安装失败
              exit 1
            fi
T
tianshuo78520a 已提交
487
        else
J
Jiabin Yang 已提交
488
          echo paddlepaddle whl包下载失败
489
          echo "wget err: $wheel_cpu_develop"
T
tianshuo78520a 已提交
490 491
          exit 1
        fi
T
tianshuo78520a 已提交
492 493 494 495
    fi
}


T
tianshuo78520a 已提交
496
function checkLinuxGPU(){
497 498
  read -n1 -p "即将检测您的机器是否含GPU,请按回车键继续..."
  echo
T
tianshuo78520a 已提交
499 500
  which nvidia-smi >/dev/null 2>&1
  if [ "$?" != "0" ];then
T
tianshuo78520a 已提交
501
    GPU='cpu'
502
    echo "未在机器上找到GPU,或PaddlePaddle暂不支持此型号的GPU"
T
tianshuo78520a 已提交
503 504
  else
    GPU='gpu'
505 506
    echo "已在您的机器上找到GPU,即将确认CUDA和CUDNN版本..."
    echo
T
tianshuo78520a 已提交
507 508
  fi
  if [ "$GPU" == 'gpu' ];then
T
tianshuo78520a 已提交
509 510
    checkLinuxCUDA
    checkLinuxCUDNN
T
tianshuo78520a 已提交
511 512 513
  fi
}

514
function linux(){
T
tianshuo78520a 已提交
515 516
gpu_list=(
"GeForce 410M"
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 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
"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")
712 713 714

  echo "Step 2. 检测GPU型号和CUDA/cuDNN版本"
  echo
T
tianshuo78520a 已提交
715
  checkLinuxGPU
716 717 718
  echo
  echo "Step 3. 检测数学库"
  echo
T
tianshuo78520a 已提交
719
  checkLinuxMathLibrary
720 721 722
  echo
  echo "Step 4. 选择要安装的PaddlePaddle版本"
  echo
T
tianshuo78520a 已提交
723
  checkLinuxPaddleVersion
724 725 726
  echo
  echo "Step 5. 检测pip版本"
  echo
J
Jiabin Yang 已提交
727
  checkLinuxPython
728
  echo
J
Jiabin Yang 已提交
729 730 731
  echo "Step 6.是否使用Python的虚拟环境"
  use_virtualenv="--user"
  checkPythonVirtualenv
732
  echo "*********************2. 开始安装*****************************"
T
tianshuo78520a 已提交
733
  PipLinuxInstall
J
Jiabin Yang 已提交
734 735 736 737 738 739 740 741 742 743
  if [ "$check_virtualenv" == 'y' ];then
    echo "虚环境创建成功,请cd 进入${virtualenv_name}, 执行 source bin/activate 进入虚环境。退出虚环境执行 deactivate命令。
  更多虚环境使用方法请参考virtualenv官网:https://virtualenv.pypa.io/en/latest/"
  fi
}

function clearMacPythonEnv(){
   python_version=""
   python_brief_version=""
   python_root=""
744
}
T
tianshuo78520a 已提交
745

746 747 748
function checkMacPython2(){
    while true
       do
749
          python_min="2.7.15"
750
          python_version=`$python_root --version 2>&1 1>&1`
J
Jiabin Yang 已提交
751
          if [[ $? == "0" ]];then
752
               if [ "$python_version" == "" ] || ( [ "$python_root" == "/usr/bin/python" ] && ( [ "$python_version" \< "$python_min" ] || ( [ "$python_version" \> "$python_min" ] && [ ${#python_version} -lt ${#python_min} ] ) ) );then
J
Jiabin Yang 已提交
753
                    clearMacPythonEnv
754 755 756
               elif [[ "$python_version" < "2.7.15" ]];then
                    echo -e "          => 在您的环境中找到 \033[32m[ $python_version ]\033[0m,此版本小于2.7.15不建议使用,请选择其他版本."
                    exit
J
Jiabin Yang 已提交
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
               else
                    check_python=`echo $python_version | grep "Python 2"`
                    if [[ -n "$check_python" ]];then
                       while true
                         do
                           echo -e "          => 在您的环境中找到 \033[32m[ $python_version ]\033[0m, 确认使用此版本请输入y;如您希望自定义Python路径请输入n。请在这里输入(y/n)并回车: "
                           read -p "" 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
                                clearMacPythonEnv
                                break
                           else
                               red "            输入错误,请重新输入(y/n)"
                           fi
                       done
                       if [[ "$use_python" == "y" ]];then
                         return 0
                       fi
                    else
                       red "          您输入Python的不是Python2"
                       clearMacPythonEnv
                    fi
               fi
784
          else
J
Jiabin Yang 已提交
785 786 787 788 789 790 791 792 793 794
               clearMacPythonEnv
               red "          => 未能在常规路径下找到可用的Python2,请使用ctrl+c命令退出安装程序,并使用brew或pypi.org下载安装Python2(注意Python版本不能低于2.7.15)"
               read -p "          如希望自定义Python路径,请输入路径
          如果希望重新选择Python版本,请回车:" python_root
               echo
               if [[ "$python_root" == "" ]];then
                     python_V=""
                     clearMacPythonEnv
                     return 1
               fi
795 796 797 798 799 800 801
          fi
       done
}

function checkMacPython3(){
    while true
       do
802
          python_min="2.7.15"
J
Jiabin Yang 已提交
803 804
          python_version=`$python_root --version 2>&1 1>&1`
          if [[ $? == "0" ]];then
805
               if [ "$python_version" == "" ] || ( [ "$python_root" == "/usr/bin/python" ] && ( [ "$python_version" \< "$python_min" ] || ( [ "$python_version" \> "$python_min" ] && [ ${#python_version} -lt ${#python_min} ] ) ) );then
J
Jiabin Yang 已提交
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833
                    clearMacPythonEnv
               else
                    check_python=`echo $python_version | grep "Python 3"`
                    if [[ -n "$check_python" ]];then
                       while true
                         do
                           echo -e "          => 在您的环境中找到 \033[32m[ $python_version ]\033[0m, 确认使用此版本请输入y;如您希望自定义Python路径请输入n。请在这里输入(y/n)并回车: "
                           read -p "" 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
                                clearMacPythonEnv
                                break
                           else
                               red "            输入错误,请重新输入(y/n)"
                           fi
                       done
                       if [[ "$use_python" == "y" ]];then
                         return 0
                       fi
                    else
                       red "          您输入Python的不是Python3"
                       clearMacPythonEnv
                    fi
               fi
834
          else
J
Jiabin Yang 已提交
835 836 837 838 839 840 841 842 843 844
               clearMacPythonEnv
               red "          => 未能在常规路径下找到可用的Python3,请使用ctrl+c命令退出安装程序,并使用brew或pypi.org下载安装Python3(注意Python版本不能低于3.5.x)"
               read -p "          如希望自定义Python路径,请输入路径
          如果希望重新选择Python版本,请回车:" python_root
               echo
               if [[ "$python_root" == "" ]];then
                     python_V=""
                     clearMacPythonEnv
                     return 1
               fi
845 846 847 848
          fi
       done
}

J
JiabinYang 已提交
849
function checkMacPaddleVersion(){
850 851 852 853 854 855 856 857
    echo
    yellow "          目前PaddlePaddle在MacOS环境下只提供稳定版,最新的版本号为 ${release_version}"
    echo
    paddle_version="2"
    echo
    yellow "          我们将会为您安装PaddlePaddle稳定版,请按回车键继续... "
    read -n1 -p ""
    echo
J
JiabinYang 已提交
858
}
J
Jiabin Yang 已提交
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873
function initCheckMacPython2(){
   echo
   yellow "          您选择了Python "$python_V",正在寻找符合要求的Python 2版本"
   echo
   python_root=`which python2.7`
   if [[ "$python_root" == "" ]];then
        python_root=`which python`
   fi
   checkMacPython2
   if [[ "$?" == "1" ]];then
        return 1
   else
        return 0
   fi
}
874

J
Jiabin Yang 已提交
875 876
function initCheckMacPython3(){
   echo
877
   yellow "          您选择了Python "$python_V",正在寻找符合您要求的Python 3版本"
J
Jiabin Yang 已提交
878 879 880 881 882 883 884 885 886
   echo
   python_root=`which python3`
   checkMacPython3
   if [[ "$?" == "1" ]];then
        return 1
   else
        return 0
   fi
}
887

J
Jiabin Yang 已提交
888 889 890 891 892 893 894 895
function checkMacPip(){
   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} == "" ]];then
            red "您输入的python:${python_root} 对应的pip不可用,请检查此pip或重新选择其他python"
            echo
            return 1
J
JiabinYang 已提交
896
       fi
J
Jiabin Yang 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911
       pip_version=`$python_root -m pip -V |awk -F '[ .]' '{print $2}'`
       if [[ 9 -le ${pip_version} ]];then
            :
       else
            red "您的pip版本过低,请安装pip 9.0.1及以上的版本"
            echo
            return 1
       fi
       if [[ "$python_brief_version" == "" ]];then
            clearMacPythonEnv
            red "您的 $python_root 对应的pip存在问题,请按ctrl + c退出后重新安装pip,或切换其他python版本"
            echo
            return 1
       else
            if [[ $python_brief_version == "27" ]];then
912
               uncode=`$python_root -c "import pip._internal;print(pip._internal.pep425tags.get_supported())"|grep "cp27"`
J
Jiabin Yang 已提交
913 914
               if [[ $uncode == "" ]];then
                  uncode="mu"
915
               else
J
Jiabin Yang 已提交
916
                  uncode="m"
917
               fi
J
Jiabin Yang 已提交
918 919 920 921 922
            fi
            version_list=`echo "${python_list[@]}" | grep "$python_brief_version" `
            if [[ "$version_list" != "" ]];then
               return 0
             else
R
Roc 已提交
923
               red "未找到可用的pip或pip3。PaddlePaddle目前支持:Python >= 3.7及其对应的pip, 请重新输入,或使用ctrl + c退出"
924
               echo
J
Jiabin Yang 已提交
925 926 927
               clearMacPythonEnv
               return 1
            fi
J
JiabinYang 已提交
928

J
Jiabin Yang 已提交
929 930 931
       fi
   fi
}
932

J
Jiabin Yang 已提交
933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
function checkMacPythonVersion(){
  while true
    do
       read -n1 -p "Step 3. 选择Python版本,请按回车键继续..."
       echo
       yellow "          2. 使用python 2.x"
       yellow "          3. 使用python 3.x"
       read -p "          => 请输入数字2或3。如输入其他字符或直接回车,将会默认使用【Python 2 】。请在这里输入并回车:" python_V
       if [[ "$python_V" == "" ]];then
            python_V="2"
       fi
       if [[ "$python_V" == "2" ]];then
            initCheckMacPython2
            if [[ "$?" == "0" ]];then
                checkMacPip
                if [[ "$?" == "0" ]];then
                    return 0
                else
                    :
                fi
T
tianshuo78520a 已提交
953
            else
J
Jiabin Yang 已提交
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
                :
            fi
       elif [[ "$python_V" == "3" ]];then
            initCheckMacPython3
            if [[ "$?" == "0" ]];then
                checkMacPip
                if [[ "$?" == "0" ]];then
                    return 0
                else
                    :
                fi
            else
                :
            fi
       else
            red "输入错误,请重新输入"
       fi
J
JiabinYang 已提交
971 972
  done
}
973 974


J
JiabinYang 已提交
975
function checkMacGPU(){
976 977
    read -n1 -p "Step 5. 选择CPU/GPU版本,请按回车键继续..."
    echo
J
JiabinYang 已提交
978
    if [[ $GPU != "" ]];then
J
Jiabin Yang 已提交
979
        yellow "          MacOS环境下,暂未提供GPU版本的PaddlePaddle安装包,将为您安装CPU版本的PaddlePaddle"
J
JiabinYang 已提交
980
    else
J
Jiabin Yang 已提交
981
        yellow "          MacOS环境下,暂未提供GPU版本的PaddlePaddle安装包,将为您安装CPU版本的PaddlePaddle"
982
        GPU=cpu
J
JiabinYang 已提交
983
    fi
984
    echo
J
JiabinYang 已提交
985
}
986

J
JiabinYang 已提交
987 988 989 990 991
function macos() {
  path='http://paddlepaddle.org/download?url='

  while true
      do
J
Jiabin Yang 已提交
992

J
JiabinYang 已提交
993
        checkMacPaddleVersion
J
Jiabin Yang 已提交
994

J
JiabinYang 已提交
995
        checkMacPythonVersion
J
Jiabin Yang 已提交
996

J
JiabinYang 已提交
997
        checkMacGPU
998 999


J
Jiabin Yang 已提交
1000
        green "*********************2. 开始安装*****************************"
1001
        echo
J
Jiabin Yang 已提交
1002 1003
        yellow "即将为您下载并安装PaddlePaddle,请按回车键继续..."
        read -n1 -p ""
J
JiabinYang 已提交
1004
        if [[ $paddle_version == "2" ]];then
1005
            $python_root -m pip install -U  paddlepaddle
J
Jiabin Yang 已提交
1006 1007
            if [[ $? == "0" ]];then
               green "安装成功,可以使用: ${python_root} 来启动安装了PaddlePaddle的Python解释器"
J
JiabinYang 已提交
1008
               break
1009
            else
J
JiabinYang 已提交
1010
               rm  $whl_cpu_release
J
Jiabin Yang 已提交
1011
               red "未能正常安装PaddlePaddle,请尝试更换您输入的python路径,或者ctrl + c退出后请检查您使用的python对应的pip或pip源是否可用"
J
JiabinYang 已提交
1012 1013 1014 1015
               echo""
               echo "=========================================================================================="
               echo""
               exit 1
1016
            fi
J
JiabinYang 已提交
1017
        else
J
Jiabin Yang 已提交
1018
            if [[ -f $whl_cpu_develop ]];then
1019
                $python_root -m pip installi -U $whl_cpu_develop
J
Jiabin Yang 已提交
1020
                if [[ $? == "0" ]];then
1021
                   rm -rf $whl_cpu_develop
J
Jiabin Yang 已提交
1022 1023
                   # TODO add install success check here
                   green "安装成功!小提示:可以使用: ${python_root} 来启动安装了PaddlePaddle的Python解释器"
1024 1025
                   break
                else
J
Jiabin Yang 已提交
1026
                   red "未能正常安装PaddlePaddle,请尝试更换您输入的python路径,或者ctrl + c退出后请检查您使用的python对应的pip或pip源是否可用"
1027 1028 1029
                   echo""
                   echo "=========================================================================================="
                   echo""
T
tianshuo78520a 已提交
1030
                   exit 1
1031 1032 1033
                fi
            else
                wget ${path}$whl_cpu_develop -O $whl_cpu_develop
J
Jiabin Yang 已提交
1034
                if [[ $? == "0" ]];then
1035
                    $python_root -m pip install $whl_cpu_develop
J
Jiabin Yang 已提交
1036
                    if [[ $? == "0" ]];then
J
JiabinYang 已提交
1037
                       rm  $wheel_cpu_develop
J
Jiabin Yang 已提交
1038
                       green "安装成功,可以使用: ${python_root} 来启动安装了PaddlePaddle的Python解释器"
1039 1040
                       break
                    else
J
JiabinYang 已提交
1041
                       rm  $whl_cpu_release
J
Jiabin Yang 已提交
1042
                       red "未能正常安装PaddlePaddle,请尝试更换您输入的python路径,或者ctrl + c退出后请检查您使用的python对应的pip或pip源是否可用"
1043 1044 1045
                       echo""
                       echo "=========================================================================================="
                       echo""
T
tianshuo78520a 已提交
1046
                       exit 1
1047 1048
                    fi
                else
J
JiabinYang 已提交
1049
                      rm  $whl_cpu_develop
J
Jiabin Yang 已提交
1050
                      red "未能正常安装PaddlePaddle,请检查您的网络 或者确认您是否安装有 wget,或者ctrl + c退出后反馈至https://github.com/PaddlePaddle/Paddle/issues"
1051 1052 1053
                      echo""
                      echo "=========================================================================================="
                      echo""
T
tianshuo78520a 已提交
1054
                      exit 1
1055 1056
                fi
            fi
J
JiabinYang 已提交
1057
        fi
1058 1059 1060 1061
  done
}

function main() {
1062
  echo "*********************************"
J
Jiabin Yang 已提交
1063
  green "欢迎使用PaddlePaddle快速安装脚本"
1064 1065
  echo "*********************************"
  echo
J
Jiabin Yang 已提交
1066
  yellow "如果您在安装过程中遇到任何问题,请在https://github.com/PaddlePaddle/Paddle/issues反馈,我们的工作人员将会帮您答疑解惑"
1067
  echo
J
Jiabin Yang 已提交
1068 1069 1070
  echo  "本安装包将帮助您在Linux或Mac系统下安装PaddlePaddle,包括"
  yellow "1)安装前的准备"
  yellow "2)开始安装"
1071 1072 1073 1074
  echo
  read -n1 -p "请按回车键进行下一步..."
  echo
  echo
J
Jiabin Yang 已提交
1075
  green "*********************1. 安装前的准备*****************************"
1076 1077 1078
  echo
  echo "Step 1. 正在检测您的操作系统信息..."
  echo
1079
  SYSTEM=`uname -s`
J
Jiabin Yang 已提交
1080 1081
  if [[ "$SYSTEM" == "Darwin" ]];then
  	yellow "          您的系统为:MAC OSX"
1082
    echo
1083 1084
  	macos
  else
J
Jiabin Yang 已提交
1085
 	yellow "          您的系统为:Linux"
1086
  echo
1087
	  OS=`cat /etc/issue|awk 'NR==1 {print $1}'`
J
Jiabin Yang 已提交
1088
	  if [[ $OS == "\S" ]] || [[ "$OS" == "CentOS" ]] || [[ $OS == "Ubuntu" ]];then
1089
	    linux
1090
	  else
J
Jiabin Yang 已提交
1091
	    red "您的系统不在本安装包的支持范围,如您需要在windows环境下安装PaddlePaddle,请您参考PaddlePaddle官网的windows安装文档"
1092 1093 1094 1095
	  fi
  fi
}
main