Debian Codegraph @

doc/usage/installation.rst

raw
1 =================
2 Installing Sphinx
3 =================
4
5 Sphinx is a Python application. It can be installed in one of the ways described
6 below.
7
8 .. contents:: Installation methods
9 :depth: 2
10 :local:
11 :backlinks: none
12
13 .. highlight:: console
14
15 After installation, you can check that Sphinx is available by running ::
16
17 $ sphinx-build --version
18
19 This should print out the Sphinx version number.
20
21
22 .. tip::
23
24 For local development, it is
25 generally recommended to install Sphinx into a non-global environment
26 (using for example `venv`__ or `conda`__ environments).
27 This will allow for the use of separate sphinx versions and third-party extensions
28 for each sphinx project.
29
30 __ https://docs.python.org/3/library/venv.html
31 __ https://conda.io/projects/conda/en/latest/user-guide/getting-started.html
32
33
34 .. _install-pypi:
35
36 PyPI package
37 ------------
38
39 Sphinx packages are published on the `Python Package Index
40 <https://pypi.org/project/Sphinx/>`_ (PyPI). The preferred tool for installing
41 packages from PyPI is :command:`pip`, which is included in all modern versions of
42 Python.
43
44 Run the following command::
45
46 $ pip install -U sphinx
47
48 .. tip::
49
50 To avoid issues when rebuilding your environment,
51 it is advisable to pin sphinx and third-party extension
52 versions in a `requirements.txt file`__::
53
54 $ pip install -r requirements.txt
55
56 Or, if writing documentation for a Python package,
57 place the dependencies in the `pyproject.toml file`__::
58
59 $ pip install . --group docs
60
61 __ https://pip.pypa.io/en/stable/reference/requirements-file-format/
62 __ https://packaging.python.org/en/latest/guides/writing-pyproject-toml/#dependencies-optional-dependencies
63
64 .. _install-conda:
65
66 Conda package
67 -------------
68 To work with :command:`conda`, you need a conda-based Python distribution such as
69 `anaconda`__, `miniconda`__, `miniforge`__ or `micromamba`__.
70
71 __ https://docs.anaconda.com/anaconda/
72 __ https://docs.anaconda.com/miniconda/
73 __ https://github.com/conda-forge/miniforge/
74 __ https://mamba.readthedocs.io/en/latest/installation/micromamba-installation.html
75
76
77 Sphinx is available both via the *anaconda main* channel (maintained by Anaconda
78 Inc.)
79
80 ::
81
82 $ conda install sphinx
83
84 as well as via the *conda-forge* community channel ::
85
86 $ conda install -c conda-forge sphinx
87
88 OS-specific package manager
89 ---------------------------
90
91 You may install a global version of Sphinx into your system using OS-specific
92 package managers. However, be aware that this is less flexible and you may run into
93 compatibility issues if you want to work across different projects.
94
95 Linux
96 ~~~~~
97
98 Debian/Ubuntu
99 """""""""""""
100
101 Install either ``python3-sphinx`` using :command:`apt-get`:
102
103 ::
104
105 $ apt-get install python3-sphinx
106
107 If it not already present, this will install Python for you.
108
109 RHEL, CentOS
110 """"""""""""
111
112 Install ``python-sphinx`` using :command:`yum`:
113
114 ::
115
116 $ yum install python-sphinx
117
118 If it not already present, this will install Python for you.
119
120 Other distributions
121 """""""""""""""""""
122
123 Most Linux distributions have Sphinx in their package repositories. Usually
124 the package is called ``python3-sphinx``, ``python-sphinx`` or ``sphinx``. Be
125 aware that there are at least two other packages with ``sphinx`` in their name:
126 a speech recognition toolkit (*CMU Sphinx*) and a full-text search database
127 (*Sphinx search*).
128
129 macOS
130 ~~~~~
131
132 Sphinx can be installed using `Homebrew`__, `MacPorts`__.
133
134 __ https://brew.sh/
135 __ https://www.macports.org/
136
137 Homebrew
138 """"""""
139
140 ::
141
142 $ brew install sphinx-doc
143
144 For more information, refer to the `package overview`__.
145
146 __ https://formulae.brew.sh/formula/sphinx-doc
147
148 MacPorts
149 """"""""
150
151 Install either ``python3x-sphinx`` using :command:`port`:
152
153 ::
154
155 $ sudo port install py314-sphinx
156
157 To set up the executable paths, use the ``port select`` command:
158
159 ::
160
161 $ sudo port select --set python python314
162 $ sudo port select --set sphinx py314-sphinx
163
164 For more information, refer to the `package overview`__.
165
166 __ https://www.macports.org/ports.php?by=library&substr=py314-sphinx
167
168 Windows
169 ~~~~~~~
170
171 Sphinx can be installed using `Chocolatey`__.
172
173 __ https://chocolatey.org/
174
175 Chocolatey
176 """"""""""
177
178 ::
179
180 $ choco install sphinx
181
182 You would need to `install Chocolatey
183 <https://chocolatey.org/install>`_
184 before running this.
185
186 For more information, refer to the `chocolatey page`__.
187
188 __ https://chocolatey.org/packages/sphinx/
189
190 Docker
191 ------
192
193 Docker images for Sphinx are published on the `Docker Hub`_. There are two kind
194 of images:
195
196 - `sphinxdoc/sphinx`_
197 - `sphinxdoc/sphinx-latexpdf`_
198
199 .. _Docker Hub: https://hub.docker.com/
200 .. _sphinxdoc/sphinx: https://hub.docker.com/r/sphinxdoc/sphinx
201 .. _sphinxdoc/sphinx-latexpdf: https://hub.docker.com/r/sphinxdoc/sphinx-latexpdf
202
203 Former one is used for standard usage of Sphinx, and latter one is mainly used for
204 PDF builds using LaTeX. Please choose one for your purpose.
205
206 .. note::
207
208 sphinxdoc/sphinx-latexpdf contains TeXLive packages. So the image is very large
209 (over 2GB!).
210
211 .. hint::
212
213 When using docker images, please use ``docker run`` command to invoke sphinx
214 commands. For example, you can use following command to create a Sphinx
215 project:
216
217 .. code-block:: console
218
219 $ docker run -it --rm -v /path/to/document:/docs sphinxdoc/sphinx sphinx-quickstart
220
221 And you can use the following command to build HTML document:
222
223 .. code-block:: console
224
225 $ docker run --rm -v /path/to/document:/docs sphinxdoc/sphinx make html
226
227 For more details, please read `README file`__ of docker images.
228
229 .. __: https://hub.docker.com/r/sphinxdoc/sphinx
230
231 Installation of the latest development release
232 ----------------------------------------------
233
234 You can install the latest development from *PyPI* using the ``--pre`` flag::
235
236 $ pip install -U --pre sphinx
237
238 .. warning::
239
240 You will not generally need (or want) to do this, but it can be
241 useful if you see a possible bug in the latest stable release.
242
243 Installation from source
244 ------------------------
245
246 You can install Sphinx directly from a clone of the `Git repository`__. This
247 can be done either by cloning the repo and installing from the local clone, on
248 simply installing directly via :command:`git`.
249
250 ::
251
252 $ git clone https://github.com/sphinx-doc/sphinx
253 $ cd sphinx
254 $ pip install .
255
256 ::
257
258 $ pip install git+https://github.com/sphinx-doc/sphinx
259
260 You can also download a snapshot of the Git repo in either `tar.gz`__ or
261 `zip`__ format. Once downloaded and extracted, these can be installed with
262 :command:`pip` as above.
263
264 .. highlight:: default
265
266 __ https://github.com/sphinx-doc/sphinx
267 __ https://github.com/sphinx-doc/sphinx/archive/master.tar.gz
268 __ https://github.com/sphinx-doc/sphinx/archive/master.zip