index.rst 7.12 KB
Newer Older
Minjie Wang's avatar
Minjie Wang committed
1
2
3
Install DGL
============

4
This topic explains how to install DGL. We recommend installing DGL by using ``conda`` or ``pip``.
Minjie Wang's avatar
Minjie Wang committed
5

Gan Quan's avatar
Gan Quan committed
6
7
System requirements
-------------------
8
DGL works with the following operating systems:
Gan Quan's avatar
Gan Quan committed
9
10
11

* Ubuntu 16.04
* macOS X
12
* Windows 10
Gan Quan's avatar
Gan Quan committed
13

14
15
DGL requires Python version 3.5 or later. Python 3.4 or earlier is not
tested. Python 2 support is coming.
Gan Quan's avatar
Gan Quan committed
16

17
18
DGL supports multiple tensor libraries as backends, e.g., PyTorch, MXNet. For requirements on backends and how to select one, see
`Working with different backends`_.
Gan Quan's avatar
Gan Quan committed
19

20
21
22
Starting at version 0.3, DGL is separated into CPU and CUDA builds.  The builds share the
same Python package name. If you install DGL with a CUDA 9 build after you install the
CPU build, then the CPU build is overwritten.
23

Gan Quan's avatar
Gan Quan committed
24
25
Install from conda
----------------------
26
27
If ``conda`` is not yet installed, get either `miniconda <https://conda.io/miniconda.html>`_ or
the full `anaconda <https://www.anaconda.com/download/>`_.
Gan Quan's avatar
Gan Quan committed
28

29
30
31
32
With ``conda`` installed, you will want install DGL into Python 3.5 ``conda`` environment.
Run `conda create -n dgl python=3.5` to create the environment.
Activate the environment by running `source activate dgl`.
After the ``conda`` environment is activated, run one of the following commands.
Minjie Wang's avatar
Minjie Wang committed
33
34
35

.. code:: bash

36
37
38
   conda install -c dglteam dgl              # For CPU Build
   conda install -c dglteam dgl-cuda9.0      # For CUDA 9.0 Build
   conda install -c dglteam dgl-cuda10.0     # For CUDA 10.0 Build
Minjie Wang's avatar
Minjie Wang committed
39

Gan Quan's avatar
Gan Quan committed
40
41
Install from pip
----------------
42
For CPU builds, run the following command to install with ``pip``.
Minjie Wang's avatar
Minjie Wang committed
43
44
45

.. code:: bash

Gan Quan's avatar
Gan Quan committed
46
   pip install dgl
47
   
48
For CUDA builds, run one of the following commands and specify the CUDA version.
49
50
51

.. code:: bash

52
53
54
55
56
   pip install dgl           # For CPU Build
   pip install dgl-cu90      # For CUDA 9.0 Build
   pip install dgl-cu92      # For CUDA 9.2 Build
   pip install dgl-cu100     # For CUDA 10.0 Build

57
For the most current nightly build from master branch, run one of the following commands.
58
59
60

.. code:: bash

61
62
63
64
65
   pip install --pre dgl           # For CPU Build
   pip install --pre dgl-cu90      # For CUDA 9.0 Build
   pip install --pre dgl-cu92      # For CUDA 9.2 Build
   pip install --pre dgl-cu100     # For CUDA 10.0 Build

Gan Quan's avatar
Gan Quan committed
66
67
68
69

Working with different backends
-------------------------------

70
DGL supports PyTorch and MXNet. Here's how to change them.
Gan Quan's avatar
Gan Quan committed
71
72
73
74
75

Switching backend
`````````````````

The backend is controlled by ``DGLBACKEND`` environment variable, which defaults to
76
``pytorch``.  The following values are supported.
Gan Quan's avatar
Gan Quan committed
77
78

+---------+---------+--------------------------------------------------+
79
| Value   | Backend | Constraints                                      |
Gan Quan's avatar
Gan Quan committed
80
+=========+=========+==================================================+
81
82
| pytorch | PyTorch | Requires 0.4.1 or later. See                     |
|         |         | `pytorch.org <https://pytorch.org>`_             |
Gan Quan's avatar
Gan Quan committed
83
+---------+---------+--------------------------------------------------+
84
| mxnet   | MXNet   | Requires either MXNet 1.5 for CPU                   |
Gan Quan's avatar
Gan Quan committed
85
86
87
|         |         |                                                  |
|         |         | .. code:: bash                                   |
|         |         |                                                  |
Da Zheng's avatar
Da Zheng committed
88
|         |         |    pip install mxnet                             |
89
|         |         |                                                  |
90
|         |         | or MXNet for GPU with CUDA version, e.g. for CUDA 9.2               |
91
92
93
|         |         |                                                  |
|         |         | .. code:: bash                                   |
|         |         |                                                  |
Da Zheng's avatar
Da Zheng committed
94
|         |         |    pip install mxnet-cu90                        |
95
|         |         |                                                  |
Gan Quan's avatar
Gan Quan committed
96
97
98
99
+---------+---------+--------------------------------------------------+
| numpy   | NumPy   | Does not support gradient computation            |
+---------+---------+--------------------------------------------------+

100
101
.. _install-from-source:

Gan Quan's avatar
Gan Quan committed
102
103
Install from source
-------------------
104
Download the source files from GitHub.
Gan Quan's avatar
Gan Quan committed
105
106

.. code:: bash
Minjie Wang's avatar
Minjie Wang committed
107

Haibin Lin's avatar
Haibin Lin committed
108
   git clone --recursive https://github.com/dmlc/dgl.git
Minjie Wang's avatar
Minjie Wang committed
109

110
(Optional) Clone the repository first, and then run the following:
Minjie Wang's avatar
Minjie Wang committed
111
112
113

.. code:: bash

Gan Quan's avatar
Gan Quan committed
114
115
116
117
118
   git submodule init
   git submodule update

Linux
`````
Minjie Wang's avatar
Minjie Wang committed
119

120
Install the system packages for building the shared library. For Debian and Ubuntu
Gan Quan's avatar
Gan Quan committed
121
users, run:
Minjie Wang's avatar
Minjie Wang committed
122
123
124

.. code:: bash

Gan Quan's avatar
Gan Quan committed
125
126
   sudo apt-get update
   sudo apt-get install -y build-essential build-dep python3-dev make cmake
Minjie Wang's avatar
Minjie Wang committed
127

Gan Quan's avatar
Gan Quan committed
128
For Fedora/RHEL/CentOS users, run:
Minjie Wang's avatar
Minjie Wang committed
129

Gan Quan's avatar
Gan Quan committed
130
131
132
.. code:: bash

   sudo yum install -y gcc-c++ python3-devel make cmake
Minjie Wang's avatar
Minjie Wang committed
133

134
135
136
Build the shared library. Use the configuration template ``cmake/config.cmake``.
Copy it to either the project directory or the build directory and change the
configuration as you wish. For example, change ``USE_CUDA`` to ``ON`` will
137
enable a CUDA build. You could also pass ``-DKEY=VALUE`` to the cmake command
138
139
for the same purpose.

140
- CPU-only build
141
142
143
144
145
146
   .. code:: bash

      mkdir build
      cd build
      cmake ..
      make -j4
147
- CUDA build
148
149
150
151
152
153
154
155
   .. code:: bash

      mkdir build
      cd build
      cmake -DUSE_CUDA=ON ..
      make -j4

Finally, install the Python binding.
Minjie Wang's avatar
Minjie Wang committed
156
157
158

.. code:: bash

Gan Quan's avatar
Gan Quan committed
159
160
161
162
163
164
   cd ../python
   python setup.py install

macOS
`````

165
Installation on macOS is similar to Linux. But macOS users need to install build tools like clang, GNU Make, and cmake first. These installation steps were tested on macOS X with clang 10.0.0, GNU Make 3.81, and cmake 3.13.1.
Minjie Wang's avatar
Minjie Wang committed
166

Gan Quan's avatar
Gan Quan committed
167
Tools like clang and GNU Make are packaged in **Command Line Tools** for macOS. To
168
install, run the following:
Minjie Wang's avatar
Minjie Wang committed
169
170
171

.. code:: bash

Gan Quan's avatar
Gan Quan committed
172
   xcode-select --install
Minjie Wang's avatar
Minjie Wang committed
173

Gan Quan's avatar
Gan Quan committed
174
To install other needed packages like cmake, we recommend first installing
175
**Homebrew**, which is a popular package manager for macOS. To learn more, see the `Homebrew website <https://brew.sh/>`_.
Gan Quan's avatar
Gan Quan committed
176

177
After you install Homebrew, install cmake.
Minjie Wang's avatar
Minjie Wang committed
178
179
180

.. code:: bash

Gan Quan's avatar
Gan Quan committed
181
   brew install cmake
Minjie Wang's avatar
Minjie Wang committed
182

183
184
Go to root directory of the DGL repository, build a shared library, and
install the Python binding for DGL.
Gan Quan's avatar
Gan Quan committed
185
186

.. code:: bash
Minjie Wang's avatar
Minjie Wang committed
187

Gan Quan's avatar
Gan Quan committed
188
189
   mkdir build
   cd build
190
   cmake -DUSE_OPENMP=off ..
Gan Quan's avatar
Gan Quan committed
191
192
193
   make -j4
   cd ../python
   python setup.py install
Minjie Wang's avatar
Minjie Wang committed
194

Gan Quan's avatar
Gan Quan committed
195
196
Windows
```````
Minjie Wang's avatar
Minjie Wang committed
197

198
The Windows source build is tested with CMake and MinGW/GCC.  We highly recommend
Gan Quan's avatar
Gan Quan committed
199
using CMake and GCC from `conda installations <https://conda.io/miniconda.html>`_.  To
200
get started, run the following:
Minjie Wang's avatar
Minjie Wang committed
201
202
203

.. code:: bash

Gan Quan's avatar
Gan Quan committed
204
205
   conda install cmake m2w64-gcc m2w64-make

206
Build the shared library and install the Python binding.
Gan Quan's avatar
Gan Quan committed
207
208
209
210
211

.. code::

   md build
   cd build
212
   cmake -DCMAKE_CXX_FLAGS="-DDMLC_LOG_STACK_TRACE=0 -DDGL_EXPORTS" -DCMAKE_MAKE_PROGRAM=mingw32-make .. -G "MSYS Makefiles"
Gan Quan's avatar
Gan Quan committed
213
214
215
   mingw32-make
   cd ..\python
   python setup.py install
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
216

217
You can also build DGL with MSBuild.  With `MS Build Tools <https://go.microsoft.com/fwlink/?linkid=840931>`_
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
218
and `CMake on Windows <https://cmake.org/download/>`_ installed, run the following
219
in VS2017 x64 Native tools command prompt.
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
220
221
222
223
224
225
226
227
228

.. code::

   MD build
   CD build
   cmake -DCMAKE_CXX_FLAGS="/DDGL_EXPORTS" -DCMAKE_CONFIGURATION_TYPES="Release" .. -G "Visual Studio 15 2017 Win64"
   msbuild dgl.sln
   cd ..\python
   python setup.py install