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

Gan Quan's avatar
Gan Quan committed
4
At this stage, we recommend installing DGL from ``conda`` or ``pip``.
Minjie Wang's avatar
Minjie Wang committed
5

Gan Quan's avatar
Gan Quan committed
6
7
8
9
10
11
System requirements
-------------------
Currently DGL is tested on

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

DGL is expected to work on all Linux distributions later than Ubuntu 16.04, macOS X, and
15
Windows 10.
Gan Quan's avatar
Gan Quan committed
16
17
18
19
20
21
22
23

DGL also requires the Python version to be 3.5 or later.  Python 3.4 or less is not
tested, and Python 2 support is coming.

DGL supports multiple tensor libraries (e.g. PyTorch, MXNet) as backends; refer
`Working with different backends`_ for requirements on backends and how to select a
backend.

24
25
26
27
Starting from 0.3 DGL is separated into CPU and CUDA builds.  The builds share the
same Python package name, so installing DGL with CUDA 9 build after installing the
CPU build will overwrite the latter.

Gan Quan's avatar
Gan Quan committed
28
29
30
31
32
33
34
Install from conda
----------------------
One can either grab `miniconda <https://conda.io/miniconda.html>`_ or
the full `anaconda <https://www.anaconda.com/download/>`_ if ``conda``
has not been installed.

Once the conda environment is activated, run
Minjie Wang's avatar
Minjie Wang committed
35
36
37

.. code:: bash

38
39
40
   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
41

Gan Quan's avatar
Gan Quan committed
42
43
Install from pip
----------------
44
For CPU builds, one can simply run the following command to install via ``pip``:
Minjie Wang's avatar
Minjie Wang committed
45
46
47

.. code:: bash

Gan Quan's avatar
Gan Quan committed
48
   pip install dgl
49
   
50
For CUDA builds, one needs to specify the CUDA version:
51
52
53

.. code:: bash

54
55
56
57
58
59
   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

We also provides nightly build from master branch, you can install it by:
60
61
62

.. code:: bash

63
64
65
66
67
   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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

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

Currently DGL supports PyTorch and MXNet.

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

The backend is controlled by ``DGLBACKEND`` environment variable, which defaults to
``pytorch``.  Currently it supports the following values:

+---------+---------+--------------------------------------------------+
| Value   | Backend | Memo                                             |
+=========+=========+==================================================+
| pytorch | PyTorch | Requires 0.4.1 or later; see                     |
|         |         | `official website <https://pytorch.org>`_        |
+---------+---------+--------------------------------------------------+
Da Zheng's avatar
Da Zheng committed
86
| mxnet   | MXNet   | Requires MXNet 1.5                               |
Gan Quan's avatar
Gan Quan committed
87
88
89
|         |         |                                                  |
|         |         | .. code:: bash                                   |
|         |         |                                                  |
Da Zheng's avatar
Da Zheng committed
90
|         |         |    pip install mxnet                             |
91
92
93
94
95
|         |         |                                                  |
|         |         | or cuda version (e.g. for cuda 9.0)              |
|         |         |                                                  |
|         |         | .. code:: bash                                   |
|         |         |                                                  |
Da Zheng's avatar
Da Zheng committed
96
|         |         |    pip install mxnet-cu90                        |
97
|         |         |                                                  |
Gan Quan's avatar
Gan Quan committed
98
99
100
101
+---------+---------+--------------------------------------------------+
| numpy   | NumPy   | Does not support gradient computation            |
+---------+---------+--------------------------------------------------+

102
103
.. _install-from-source:

Gan Quan's avatar
Gan Quan committed
104
105
106
107
108
Install from source
-------------------
First, download the source files from GitHub:

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

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

Gan Quan's avatar
Gan Quan committed
112
One can also clone the repository first and run the following:
Minjie Wang's avatar
Minjie Wang committed
113
114
115

.. code:: bash

Gan Quan's avatar
Gan Quan committed
116
117
118
119
120
   git submodule init
   git submodule update

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

Gan Quan's avatar
Gan Quan committed
122
123
Install the system packages for building the shared library, for Debian/Ubuntu
users, run:
Minjie Wang's avatar
Minjie Wang committed
124
125
126

.. code:: bash

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

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

Gan Quan's avatar
Gan Quan committed
132
133
134
.. code:: bash

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

136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
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
enable cuda build. You could also pass ``-DKEY=VALUE`` to the cmake command
for the same purpose.

- CPU-only build:
   .. code:: bash

      mkdir build
      cd build
      cmake ..
      make -j4
- Cuda build:
   .. code:: bash

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

Finally, install the Python binding.
Minjie Wang's avatar
Minjie Wang committed
158
159
160

.. code:: bash

Gan Quan's avatar
Gan Quan committed
161
162
163
164
165
166
167
168
   cd ../python
   python setup.py install

macOS
`````

Installation on macOS is similar to Linux. But macOS users need to install
building tools like clang, GNU Make, cmake first.
Minjie Wang's avatar
Minjie Wang committed
169

Gan Quan's avatar
Gan Quan committed
170
171
Tools like clang and GNU Make are packaged in **Command Line Tools** for macOS. To
install:
Minjie Wang's avatar
Minjie Wang committed
172
173
174

.. code:: bash

Gan Quan's avatar
Gan Quan committed
175
   xcode-select --install
Minjie Wang's avatar
Minjie Wang committed
176

Gan Quan's avatar
Gan Quan committed
177
178
179
180
181
To install other needed packages like cmake, we recommend first installing
**Homebrew**, which is a popular package manager for macOS. Detailed
instructions can be found on its `homepage <https://brew.sh/>`_.

After installation of Homebrew, install cmake by:
Minjie Wang's avatar
Minjie Wang committed
182
183
184

.. code:: bash

Gan Quan's avatar
Gan Quan committed
185
   brew install cmake
Minjie Wang's avatar
Minjie Wang committed
186

Gan Quan's avatar
Gan Quan committed
187
188
189
190
Then go to root directory of DGL repository, build shared library and
install Python binding for DGL:

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

Gan Quan's avatar
Gan Quan committed
192
193
   mkdir build
   cd build
194
   cmake -DUSE_OPENMP=off ..
Gan Quan's avatar
Gan Quan committed
195
196
197
   make -j4
   cd ../python
   python setup.py install
Minjie Wang's avatar
Minjie Wang committed
198

Gan Quan's avatar
Gan Quan committed
199
200
We tested installation on macOS X with clang 10.0.0, GNU Make 3.81, and cmake
3.13.1.
Minjie Wang's avatar
Minjie Wang committed
201

Gan Quan's avatar
Gan Quan committed
202
203
Windows
```````
Minjie Wang's avatar
Minjie Wang committed
204

Gan Quan's avatar
Gan Quan committed
205
206
207
Currently Windows source build is tested with CMake and MinGW/GCC.  We highly recommend
using CMake and GCC from `conda installations <https://conda.io/miniconda.html>`_.  To
do so, run
Minjie Wang's avatar
Minjie Wang committed
208
209
210

.. code:: bash

Gan Quan's avatar
Gan Quan committed
211
212
213
214
215
216
217
218
   conda install cmake m2w64-gcc m2w64-make

Then build the shared library and install the Python binding:

.. code::

   md build
   cd build
219
   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
220
221
222
   mingw32-make
   cd ..\python
   python setup.py install
Quan (Andy) Gan's avatar
Quan (Andy) Gan committed
223
224
225
226
227
228
229
230
231
232
233
234
235

We also support building DGL with MSBuild.  With `MS Build Tools <https://go.microsoft.com/fwlink/?linkid=840931>`_
and `CMake on Windows <https://cmake.org/download/>`_ installed, run the following
in VS2017 x64 Native tools command prompt:

.. 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