335 Star 1.5K Fork 857

MindSpore / docs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
mindspore_cpu_install_pip_en.md 8.39 KB
一键复制 编辑 原始数据 按行查看 历史
yanghaoran 提交于 2023-10-17 20:52 . update version 2.2.0

Installing MindSpore in CPU by pip

View Source On Gitee

This document describes how to install MindSpore by pip on Linux in a CPU environment. The following takes Ubuntu 18.04 as an example to describe how to install MindSpore.

  • If you want to install MindSpore by pip on a fresh Ubuntu 18.04, you may use an automatic installation script for one-click installation. For details, see Automatic Installation. The script will automatically install MindSpore and its dependencies.

  • If some dependencies, such as Python and GCC, have been installed in your system, it is recommended to install manually by referring to the installation steps in the Manual Installation.

Automatic Installation

The root permission is required because the automatic installation script needs to change the software source configuration and install dependencies via APT. Run the following command to obtain and run the automatic installation script. The automatic installation script supports only MindSpore>=1.6.0 or later.

wget https://gitee.com/mindspore/mindspore/raw/master/scripts/install/ubuntu-cpu-pip.sh
# install MindSpore 2.2.0 and Python 3.7
MINDSPORE_VERSION=2.2.0 bash ./ubuntu-cpu-pip.sh
# to specify Python and MindSpore version, taking Python 3.9 and MindSpore 1.6.0 as examples, use the following manners
# PYTHON_VERSION=3.9 MINDSPORE_VERSION=1.6.0 bash ./ubuntu-cpu-pip.sh

This script performs the following operations:

  • Change the software source configuration to a HUAWEI CLOUD source
  • Install the dependencies required by MindSpore, such as GCC.
  • Install Python3 and pip3 via APT and set them as default.
  • Install MindSpore in CPU by pip.

After the automatic installation script is executed, you need to reopen the terminal window to make the environment variables take effect.

For more usage, see the script header description.

Manual Installation

The following table lists the system environment and third-party dependencies required to install MindSpore.

Software Version Description
Ubuntu 18.04 OS for running MindSpore
Python 3.7-3.9 Python environment that MindSpore depends
GCC 7.3.0~9.4.0 C++ compiler for compiling MindSpore

The following describes how to install the third-party dependencies.

Installing Python

Python can be installed in multiple ways.

  • Install Python with Conda.

    Install Miniconda:

    cd /tmp
    curl -O https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py37_4.10.3-Linux-$(arch).sh
    bash Miniconda3-py37_4.10.3-Linux-$(arch).sh -b
    cd -
    . ~/miniconda3/etc/profile.d/conda.sh
    conda init bash

    After the installation is complete, you can set up Tsinghua source acceleration download for Conda, and see here.

    Create a virtual environment, taking Python 3.7.5 as an example:

    conda create -n mindspore_py37 python=3.7.5 -y
    conda activate mindspore_py37
  • Or install Python via APT with the following command.

    sudo apt-get update
    sudo apt-get install software-properties-common -y
    sudo add-apt-repository ppa:deadsnakes/ppa -y
    sudo apt-get install python3.7 python3.7-dev python3.7-distutils python3-pip -y
    # set new installed Python as default
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 100
    # install pip
    python -m pip install pip -i https://repo.huaweicloud.com/repository/pypi/simple
    sudo update-alternatives --install /usr/bin/pip pip ~/.local/bin/pip3.7 100
    pip config set global.index-url https://repo.huaweicloud.com/repository/pypi/simple

    To install other Python versions, just change 3.7 in the command.

Run the following command to check the Python version.

python --version

Installing GCC

Run the following commands to install GCC.

sudo apt-get install gcc-7 -y

To install a later version of GCC, run the following command to install GCC 8.

sudo apt-get install gcc-8 -y

Or install GCC 9.

sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-9 -y

Installing MindSpore

First, refer to Version List to select the version of MindSpore you want to install, and perform SHA-256 integrity check. Taking version 2.2.0 as an example, execute the following commands.

export MS_VERSION=2.2.0

Then run the following commands to install MindSpore according to the system architecture and Python version.

# x86_64 + Python3.7
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/unified/x86_64/mindspore-${MS_VERSION/-/}-cp37-cp37m-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# x86_64 + Python3.8
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/unified/x86_64/mindspore-${MS_VERSION/-/}-cp38-cp38-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# x86_64 + Python3.9
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/unified/x86_64/mindspore-${MS_VERSION/-/}-cp39-cp39-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# aarch64 + Python3.7
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/unified/aarch64/mindspore-${MS_VERSION/-/}-cp37-cp37m-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# aarch64 + Python3.8
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/unified/aarch64/mindspore-${MS_VERSION/-/}-cp38-cp38-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
# aarch64 + Python3.9
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/unified/aarch64/mindspore-${MS_VERSION/-/}-cp39-cp39-linux_aarch64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple

When the network is connected, dependency items are automatically downloaded during .whl package installation. (For details about the dependency, see required_package in setup.py.) In other cases, you need to install it by yourself. When running models, you need to install additional dependencies based on requirements.txt specified for different models in ModelZoo. For details about common dependencies, see requirements.txt.

Installation Verification

python -c "import mindspore;mindspore.set_context(device_target='CPU');mindspore.run_check()"

The outputs should be the same as:

MindSpore version: __version__
The result of multiplication calculation is correct, MindSpore has been installed on platform [CPU] successfully!

It means MindSpore has been installed successfully.

Version Update

Use the following command if you need to update the MindSpore version:

pip install --upgrade mindspore=={version}

Of which,

  • When updating to a release candidate (RC) version, set {version} to the RC version number, for example, 2.0.0.rc1. When updating to a stable release, you can remove =={version}.
1
https://gitee.com/mindspore/docs.git
git@gitee.com:mindspore/docs.git
mindspore
docs
docs
master

搜索帮助