2018-02-06 14:22:10 -06:00
|
|
|
=================
|
2013-01-18 16:17:11 -06:00
|
|
|
Installing Sphinx
|
2013-03-29 05:45:07 -05:00
|
|
|
=================
|
2013-01-18 16:17:11 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
.. contents::
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
:backlinks: none
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
.. highlight:: console
|
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Overview
|
|
|
|
--------
|
2013-01-18 16:17:11 -06:00
|
|
|
|
2020-06-03 10:18:30 -05:00
|
|
|
Sphinx is written in `Python`__ and supports Python 3.6+. It builds upon the
|
2020-05-29 11:50:24 -05:00
|
|
|
shoulders of many third-party libraries such as `Docutils`__ and `Jinja`__,
|
|
|
|
which are installed when Sphinx is installed.
|
2013-01-18 16:17:11 -06:00
|
|
|
|
2018-09-23 11:36:25 -05:00
|
|
|
__ https://docs.python-guide.org/
|
2020-05-29 11:50:24 -05:00
|
|
|
__ https://docutils.sourceforge.io/
|
|
|
|
__ https://jinja.palletsprojects.com/
|
2013-01-18 16:17:11 -06:00
|
|
|
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Linux
|
|
|
|
-----
|
|
|
|
|
|
|
|
Debian/Ubuntu
|
|
|
|
~~~~~~~~~~~~~
|
|
|
|
|
2020-02-23 21:39:57 -06:00
|
|
|
Install either ``python3-sphinx`` using :command:`apt-get`:
|
2018-02-06 14:22:10 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2018-02-06 14:22:10 -06:00
|
|
|
|
|
|
|
$ apt-get install python3-sphinx
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
If it not already present, this will install Python for you.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
RHEL, CentOS
|
|
|
|
~~~~~~~~~~~~
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Install ``python-sphinx`` using :command:`yum`:
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
$ yum install python-sphinx
|
|
|
|
|
|
|
|
If it not already present, this will install Python for you.
|
|
|
|
|
|
|
|
Other distributions
|
|
|
|
~~~~~~~~~~~~~~~~~~~
|
2013-03-29 05:45:07 -05:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Most Linux distributions have Sphinx in their package repositories. Usually
|
|
|
|
the package is called ``python3-sphinx``, ``python-sphinx`` or ``sphinx``. Be
|
|
|
|
aware that there are at least two other packages with ``sphinx`` in their name:
|
|
|
|
a speech recognition toolkit (*CMU Sphinx*) and a full-text search database
|
|
|
|
(*Sphinx search*).
|
2013-03-29 05:45:07 -05:00
|
|
|
|
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
macOS
|
|
|
|
-----
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-17 16:56:53 -05:00
|
|
|
Sphinx can be installed using `Homebrew`__, `MacPorts`__, or as part of
|
|
|
|
a Python distribution such as `Anaconda`__.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
__ https://brew.sh/
|
|
|
|
__ https://www.macports.org/
|
2018-03-17 16:56:53 -05:00
|
|
|
__ https://www.anaconda.com/download/#macos
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Homebrew
|
|
|
|
~~~~~~~~
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
$ brew install sphinx-doc
|
|
|
|
|
|
|
|
For more information, refer to the `package overview`__.
|
|
|
|
|
2018-09-23 11:36:25 -05:00
|
|
|
__ https://formulae.brew.sh/formula/sphinx-doc
|
2018-02-06 14:22:10 -06:00
|
|
|
|
|
|
|
MacPorts
|
|
|
|
~~~~~~~~
|
|
|
|
|
2020-02-23 21:43:45 -06:00
|
|
|
Install either ``python3x-sphinx`` using :command:`port`:
|
2018-02-06 14:22:10 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2018-02-06 14:22:10 -06:00
|
|
|
|
2020-02-23 21:43:45 -06:00
|
|
|
$ sudo port install py38-sphinx
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2013-03-29 05:45:07 -05:00
|
|
|
To set up the executable paths, use the ``port select`` command:
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2020-02-23 21:43:45 -06:00
|
|
|
$ sudo port select --set python python38
|
|
|
|
$ sudo port select --set sphinx py38-sphinx
|
2018-02-06 14:22:10 -06:00
|
|
|
|
|
|
|
For more information, refer to the `package overview`__.
|
|
|
|
|
2020-02-23 21:43:45 -06:00
|
|
|
__ https://www.macports.org/ports.php?by=library&substr=py38-sphinx
|
2018-02-06 14:22:10 -06:00
|
|
|
|
2018-03-17 16:56:53 -05:00
|
|
|
Anaconda
|
|
|
|
~~~~~~~~
|
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2018-03-17 16:56:53 -05:00
|
|
|
|
|
|
|
$ conda install sphinx
|
2018-02-06 14:22:10 -06:00
|
|
|
|
|
|
|
Windows
|
|
|
|
-------
|
|
|
|
|
2021-03-06 12:51:41 -06:00
|
|
|
Sphinx can be install using `Chocolatey`__ or
|
|
|
|
:ref:`installed manually <windows-other-method>`.
|
2021-03-06 12:43:40 -06:00
|
|
|
|
|
|
|
__ https://chocolatey.org/
|
|
|
|
|
|
|
|
Chocolatey
|
|
|
|
~~~~~~~~~~
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
$ choco install sphinx
|
|
|
|
|
|
|
|
You would need to `install Chocolatey
|
2021-10-27 11:39:40 -05:00
|
|
|
<https://chocolatey.org/install>`_
|
2021-03-06 12:43:40 -06:00
|
|
|
before running this.
|
|
|
|
|
|
|
|
For more information, refer to the `chocolatey page`__.
|
|
|
|
|
|
|
|
__ https://chocolatey.org/packages/sphinx/
|
|
|
|
|
|
|
|
.. _windows-other-method:
|
|
|
|
|
|
|
|
Other Methods
|
|
|
|
~~~~~~~~~~~~~
|
2018-02-06 14:22:10 -06:00
|
|
|
|
|
|
|
Most Windows users do not have Python installed by default, so we begin with
|
2019-07-05 20:41:22 -05:00
|
|
|
the installation of Python itself. To check if you already have Python
|
|
|
|
installed, open the *Command Prompt* (:kbd:`⊞Win-r` and type :command:`cmd`).
|
|
|
|
Once the command prompt is open, type :command:`python --version` and press
|
|
|
|
Enter. If Python is installed, you will see the version of Python printed to
|
|
|
|
the screen. If you do not have Python installed, refer to the `Hitchhikers
|
|
|
|
Guide to Python's`__ Python on Windows installation guides. You must install
|
|
|
|
`Python 3`__.
|
2018-02-06 14:22:10 -06:00
|
|
|
|
|
|
|
Once Python is installed, you can install Sphinx using :command:`pip`. Refer
|
|
|
|
to the :ref:`pip installation instructions <install-pypi>` below for more
|
|
|
|
information.
|
|
|
|
|
2018-09-23 11:36:25 -05:00
|
|
|
__ https://docs.python-guide.org/
|
|
|
|
__ https://docs.python-guide.org/starting/install3/win/
|
2018-02-06 14:22:10 -06:00
|
|
|
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
.. _install-pypi:
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Installation from PyPI
|
|
|
|
----------------------
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Sphinx packages are published on the `Python Package Index
|
2018-04-18 21:51:48 -05:00
|
|
|
<https://pypi.org/project/Sphinx/>`_. The preferred tool for installing
|
2018-02-06 14:22:10 -06:00
|
|
|
packages from *PyPI* is :command:`pip`. This tool is provided with all modern
|
|
|
|
versions of Python.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
On Linux or MacOS, you should open your terminal and run the following command.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
$ pip install -U sphinx
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-28 20:04:05 -05:00
|
|
|
On Windows, you should open *Command Prompt* (:kbd:`⊞Win-r` and type
|
2018-02-06 14:22:10 -06:00
|
|
|
:command:`cmd`) and run the same command.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
.. code-block:: doscon
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
C:\> pip install -U sphinx
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
After installation, type :command:`sphinx-build --version` on the command
|
|
|
|
prompt. If everything worked fine, you will see the version number for the
|
|
|
|
Sphinx package you just installed.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Installation from *PyPI* also allows you to install the latest development
|
|
|
|
release. You will not generally need (or want) to do this, but it can be
|
|
|
|
useful if you see a possible bug in the latest stable release. To do this, use
|
|
|
|
the ``--pre`` flag.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
$ pip install -U --pre sphinx
|
2014-12-03 08:17:48 -06:00
|
|
|
|
2021-05-29 12:15:15 -05:00
|
|
|
Using virtual environments
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
When installing Sphinx using pip,
|
|
|
|
it is highly recommended to use *virtual environments*,
|
2021-05-31 08:48:57 -05:00
|
|
|
which isolate the installed packages from the system packages,
|
|
|
|
thus removing the need to use administrator privileges.
|
2021-05-29 12:15:15 -05:00
|
|
|
To create a virtual environment in the ``.venv`` directory,
|
|
|
|
use the following command.
|
|
|
|
|
|
|
|
::
|
|
|
|
|
|
|
|
$ python -m venv .venv
|
|
|
|
|
|
|
|
You can read more about them in the `Python Packaging User Guide`_.
|
|
|
|
|
|
|
|
.. _Python Packaging User Guide: https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment
|
|
|
|
|
|
|
|
.. warning::
|
|
|
|
|
2021-05-31 08:48:57 -05:00
|
|
|
Note that in some Linux distributions, such as Debian and Ubuntu,
|
|
|
|
this might require an extra installation step as follows.
|
|
|
|
|
2021-05-31 11:03:04 -05:00
|
|
|
.. code-block:: console
|
2021-05-29 12:15:15 -05:00
|
|
|
|
2021-05-31 11:03:04 -05:00
|
|
|
$ apt-get install python3-venv
|
2014-12-03 08:17:48 -06:00
|
|
|
|
2020-02-24 21:47:14 -06:00
|
|
|
Docker
|
|
|
|
------
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2021-06-05 22:52:44 -05:00
|
|
|
Docker images for Sphinx are published on the `Docker Hub`_. There are two kind
|
|
|
|
of images:
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2021-06-05 22:52:44 -05:00
|
|
|
- `sphinxdoc/sphinx`_
|
|
|
|
- `sphinxdoc/sphinx-latexpdf`_
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2021-06-05 22:52:44 -05:00
|
|
|
.. _Docker Hub: https://hub.docker.com/
|
2021-11-01 07:31:47 -05:00
|
|
|
.. _sphinxdoc/sphinx: https://hub.docker.com/r/sphinxdoc/sphinx
|
|
|
|
.. _sphinxdoc/sphinx-latexpdf: https://hub.docker.com/r/sphinxdoc/sphinx-latexpdf
|
2021-06-05 22:52:44 -05:00
|
|
|
|
|
|
|
Former one is used for standard usage of Sphinx, and latter one is mainly used for
|
|
|
|
PDF builds using LaTeX. Please choose one for your purpose.
|
2020-02-24 00:41:27 -06:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
2021-06-05 22:52:44 -05:00
|
|
|
sphinxdoc/sphinx-latexpdf contains TeXLive packages. So the image is very large
|
|
|
|
(over 2GB!).
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2020-02-29 01:22:55 -06:00
|
|
|
.. hint::
|
2020-02-24 21:47:14 -06:00
|
|
|
|
2021-06-05 22:52:44 -05:00
|
|
|
When using docker images, please use ``docker run`` command to invoke sphinx
|
|
|
|
commands. For example, you can use following command to create a Sphinx
|
|
|
|
project:
|
|
|
|
|
2021-12-12 22:15:58 -06:00
|
|
|
.. code-block:: console
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2020-03-25 05:18:18 -05:00
|
|
|
$ docker run -it --rm -v /path/to/document:/docs sphinxdoc/sphinx sphinx-quickstart
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2021-12-04 06:13:17 -06:00
|
|
|
And you can use the following command to build HTML document:
|
2021-06-05 22:52:44 -05:00
|
|
|
|
2021-12-12 22:15:58 -06:00
|
|
|
.. code-block:: console
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2020-02-29 01:22:55 -06:00
|
|
|
$ docker run --rm -v /path/to/document:/docs sphinxdoc/sphinx make html
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2020-02-29 01:22:55 -06:00
|
|
|
For more details, please read `README file`__ of docker images.
|
2020-02-24 00:41:27 -06:00
|
|
|
|
2021-11-01 07:31:47 -05:00
|
|
|
.. __: https://hub.docker.com/r/sphinxdoc/sphinx
|
2020-02-29 01:16:56 -06:00
|
|
|
|
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
Installation from source
|
|
|
|
------------------------
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
You can install Sphinx directly from a clone of the `Git repository`__. This
|
|
|
|
can be done either by cloning the repo and installing from the local clone, on
|
|
|
|
simply installing directly via :command:`git`.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
$ git clone https://github.com/sphinx-doc/sphinx
|
|
|
|
$ cd sphinx
|
|
|
|
$ pip install .
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
::
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
$ pip install git+https://github.com/sphinx-doc/sphinx
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
You can also download a snapshot of the Git repo in either `tar.gz`__ or
|
|
|
|
`zip`__ format. Once downloaded and extracted, these can be installed with
|
|
|
|
:command:`pip` as above.
|
2013-01-20 01:06:04 -06:00
|
|
|
|
2018-03-30 02:13:50 -05:00
|
|
|
.. highlight:: default
|
|
|
|
|
2018-02-06 14:22:10 -06:00
|
|
|
__ https://github.com/sphinx-doc/sphinx
|
|
|
|
__ https://github.com/sphinx-doc/sphinx/archive/master.tar.gz
|
|
|
|
__ https://github.com/sphinx-doc/sphinx/archive/master.zip
|