mindspore/scripts/install/ubuntu-cpu-pip.sh

84 lines
3.5 KiB
Bash
Raw Normal View History

2022-02-15 19:50:32 +08:00
#!/bin/bash
# Copyright 2022 Huawei Technologies Co., Ltd
#
# 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.
# ============================================================================
# Prepare and Install mindspore cpu by pip on Ubuntu 18.04.
#
# This file will:
# - change deb source to huaweicloud mirror
# - install mindspore dependencies via apt like gcc, libgmp
# - install python3 & pip3 via apt and set it to default
# - install mindspore-cpu within new installed python by pip
#
# Augments:
2022-03-24 10:19:54 +08:00
# - PYTHON_VERSION: python version to install. [3.7(default), 3.8, 3.9]
2022-03-31 11:06:01 +08:00
# - MINDSPORE_VERSION: mindspore version to install, >=1.6.0, required
2022-02-15 19:50:32 +08:00
#
# Usage:
2022-03-31 11:06:01 +08:00
# Run script like `MINDSPORE_VERSION=1.7.0 bash ./ubuntu-cpu-pip.sh`.
# To set augments, run it as `PYTHON_VERSION=3.9 MINDSPORE_VERSION=1.6.0 bash ./ubuntu-cpu-pip.sh`.
2022-02-15 19:50:32 +08:00
set -e
PYTHON_VERSION=${PYTHON_VERSION:-3.7}
MINDSPORE_VERSION=${MINDSPORE_VERSION:-EMPTY}
2022-03-31 11:06:01 +08:00
version_less() {
test "$(echo "$@" | tr ' ' '\n' | sort -rV | head -n 1)" != "$1";
}
if [ $MINDSPORE_VERSION == "EMPTY" ] || version_less "${MINDSPORE_VERSION}" "1.6.0"; then
echo "MINDSPORE_VERSION should be >=1.6.0, please check available versions at https://www.mindspore.cn/versions."
exit 1
fi
2022-02-15 19:50:32 +08:00
2022-03-24 10:19:54 +08:00
available_py_version=(3.7 3.8 3.9)
2022-02-15 19:50:32 +08:00
if [[ " ${available_py_version[*]} " != *" $PYTHON_VERSION "* ]]; then
echo "PYTHON_VERSION is '$PYTHON_VERSION', but available versions are [${available_py_version[*]}]."
exit 1
fi
2022-03-31 11:06:01 +08:00
if [[ "$PYTHON_VERSION" == "3.8" && ${MINDSPORE_VERSION:0:3} == "1.6" ]]; then
echo "PYTHON_VERSION==3.8 is not compatible with MINDSPORE_VERSION==1.6.x, please use PYTHON_VERSION==3.7 or 3.9 for MINDSPORE_VERSION==1.6.x."
exit 1
fi
2022-02-15 19:50:32 +08:00
declare -A version_map=()
2022-03-31 11:06:01 +08:00
version_map["3.7"]="${MINDSPORE_VERSION/-/}-cp37-cp37m"
version_map["3.8"]="${MINDSPORE_VERSION/-/}-cp38-cp38"
version_map["3.9"]="${MINDSPORE_VERSION/-/}-cp39-cp39"
2022-02-15 19:50:32 +08:00
# use huaweicloud mirror in China
2022-03-24 10:19:54 +08:00
sudo sed -i "s@http://.*archive.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo sed -i "s@http://.*security.ubuntu.com@http://repo.huaweicloud.com@g" /etc/apt/sources.list
sudo apt-get update
sudo apt-get install gcc-7 libgmp-dev -y
2022-02-15 19:50:32 +08:00
# python
2022-03-24 10:19:54 +08:00
sudo add-apt-repository -y ppa:deadsnakes/ppa
sudo apt-get install python$PYTHON_VERSION python$PYTHON_VERSION-distutils python3-pip -y
sudo update-alternatives --install /usr/bin/python python /usr/bin/python$PYTHON_VERSION 100
2022-02-15 19:50:32 +08:00
# pip
2022-03-24 10:19:54 +08:00
python -m pip install -U pip -i https://pypi.tuna.tsinghua.edu.cn/simple
echo -e "alias pip='python -m pip'" >> ~/.bashrc
2022-03-30 09:27:27 +08:00
python -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
2022-02-15 19:50:32 +08:00
# install mindspore whl
arch=`uname -m`
2022-03-30 09:27:27 +08:00
python -m pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MINDSPORE_VERSION}/MindSpore/cpu/${arch}/mindspore-${version_map["$PYTHON_VERSION"]}-linux_${arch}.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
2022-02-15 19:50:32 +08:00
# check mindspore installation
2022-03-24 10:19:54 +08:00
python -c "import mindspore;mindspore.run_check()"