This document describes how to install MindSpore by compiling source code on Linux system in the CPU environment. The following takes Ubuntu 18.04 as an example to describe how to compile and install MindSpore.
If you need to configure an environment for building MindSpore on the Ubuntu 18.04 that never installed MindSpore and its dependencies, you may use an automatic installation script for one-click configuration, see Environment Preparation -automatic, recommended section. The script installs the dependencies required for building MindSpore.
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 Environment Preparation-manual section.
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 environment configured by the automatic installation script only supports compiling MindSpore>=1.6.0.
wget https://gitee.com/mindspore/mindspore/raw/master/scripts/install/ubuntu-cpu-source.sh
# install Python 3.7 by default
bash ./ubuntu-cpu-source.sh
# to specify Python version, taking Python 3.9 as an example, use the following manner
# PYTHON_VERSION=3.9 bash ./ubuntu-cpu-source.sh
This script performs the following operations:
After the automatic installation script is executed, you need to reopen the terminal window to make the environment variables take effect, then move on to Downloading the Source Code from the Code Repository to compile MindSpore from source code.
For more usage, see the script header description.
Software | Version | Description |
---|---|---|
Ubuntu | 18.04 | OS for compiling and running MindSpore |
Python | 3.7-3.9 | Python environment that MindSpore depends |
wheel | 0.32.0 or later | Python packaging tool used by MindSpore |
setuptools | 44.0 or later | Python package management tool used by MindSpore |
GCC | 7.3.0~9.4.0 | C++ compiler for compiling MindSpore |
git | - | Source code management tools used by MindSpore |
CMake | 3.18.3 or later | Compilation tool that builds MindSpore |
tclsh | - | MindSpore SQLite compilation dependency |
patch | 2.5 or later | Source code patching tool used by MindSpore |
NUMA | 2.0.11 or later | Non-uniform memory access library used by MindSpore |
LLVM | 12.0.1 | Compiler framework used by MindSpore (optional, mandatory for graph kernel fusion and sparse computing) |
The following describes how to install the third-party dependencies.
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
After installing Python, run the following command to install them.
pip install wheel
pip install -U setuptools
Run the following commands to install GCC, git, tclsh, patch and NUMA.
sudo apt-get install gcc-7 git tcl patch libnuma-dev -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
Run the following command to install CMake.
wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add -
sudo apt-add-repository "deb https://apt.kitware.com/ubuntu/ $(lsb_release -cs) main"
sudo apt-get install cmake -y
Run the following command to install LLVM.
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-12 main"
sudo apt-get update
sudo apt-get install llvm-12-dev -y
git clone https://gitee.com/mindspore/mindspore.git
Go to the root directory of mindspore, then run the compilation script.
cd mindspore
bash build.sh -e cpu -j4 -S on
Where:
-j{Number of threads}
to increase the number of threads. For example, bash build.sh -e cpu -j12
.on
, the source code is downloaded from the corresponding Gitee image.build.sh
, see the script header description.pip install output/mindspore-*.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
When the network is connected, dependencies of MindSpore are automatically downloaded during the .whl package installation. For details about dependencies, see required_package in the setup.py. In other cases, install the dependencies by yourself. When running a model, you need to install additional dependencies based on the requirements.txt file specified by different models in the ModelZoo. For details about common dependencies, see requirements.txt.
python -c "import mindspore;mindspore.set_context(device_target='CPU');mindspore.run_check()"
The output should be like:
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.
After successfully executing the compile script build.sh
in the root path of the source code, find the whl package in path output
, and use the following command to update your version.
pip install --upgrade mindspore*.whl
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。