Sphinxのインストール

概要

Sphinx is written in Python and supports Python 3.9+. It builds upon the shoulders of many third-party libraries such as Docutils and Jinja, which are installed when Sphinx is installed.

Linux

Debian/Ubuntu

apt-get: コマンドで python3-sphinx をインストールしてください。

$ apt-get install python3-sphinx

もしPythonがインストールされていなくても、このコマンドで一緒にインストールされます。

RHEL, CentOS

yum コマンドで python-sphinx をインストールしてください:

$ yum install python-sphinx

もしPythonがインストールされていなくても、このコマンドで一緒にインストールされます。

他のディストリビューション

ほとんどのLinuxディストリビューションは、OSのパッケージ管理リポジトリにSphinxが用意されています。一般的なパッケージ名は python3-sphinx, python-sphinx, sphinx のいずれかです。 sphinx という名前をもつ別の用途のパッケージが他に2つあることに注意してください: 音声認識ツールキット(CMU Sphinx), フルテキスト検索データベース(Sphinx search)。

macOS

HomebrewMacPorts でSphinxをインストールできます。あるいは、Pythonの配布形態の1つである Anaconda でもインストールできます。

Homebrew

$ brew install sphinx-doc

詳しくは、 package overview を参照してください。

MacPorts

port: コマンドで python3x-sphinx をインストールしてください。

$ sudo port install py39-sphinx

実行パスを設定するために port select コマンドを使って下さい:

$ sudo port select --set python python39
$ sudo port select --set sphinx py39-sphinx

詳しくは、 package overview を参照してください。

Anaconda

$ conda install sphinx

Windows

Sphinx can be install using Chocolatey or installed manually.

Chocolatey

$ choco install sphinx

You would need to install Chocolatey before running this.

For more information, refer to the chocolatey page.

Other Methods

ほとんどのWindowsユーザはPythonをデフォルトでインストールしていないので、Python自体のインストールから始めます。Pythonがすでにインストールされているかどうかを調べるには、 (⊞Win-r およびタイプ cmd で) Command Prompt を開きます。コマンドプロンプトが開いたら、 python --version と入力してEnterを押します。Pythonがインストールされている場合は、Pythonのバージョンが画面に出力されます。Pythonがインストールされていない場合は、 Hitchhikers Guide to Python's Python on Windowsインストール・ガイドを参照してください。 Python 3 をインストールする必要があります。

Pythonがインストールされたら、 pip を使ってSphinxをインストールすることができます。詳細は以下の pip installation instructions を参照してください。

PyPIからインストール

Sphinxのパッケージは Python Package Index に公開されています。 PyPI からパッケージをインストールするには pip を使うことをお勧めします。このツールは最近のバージョンのPythonすべてに付属しています。

LinuxまたはMacOSの場合は、ターミナルを開いて次のコマンドを実行します。

$ pip install -U sphinx

Windowsでは、( ⊞Win-r および cmd タイプにより) Command Prompt を開いて同じコマンドを実行します。

C:\> pip install -U sphinx

インストール後、コマンド・プロンプトで sphinx-build --version と入力します。問題がなければ、インストールしたSphinxパッケージのバージョン番号が表示されます。

PyPI からのインストールでは、最新の開発リリースをインストールすることもできます。一般的にこれを行うのに(または)は必要ありませんが、最新の安定版リリースにバグの可能性がある場合には便利です。これを行うには、 --pre フラグを使用します。

$ pip install -U --pre sphinx

Using virtual environments

When installing Sphinx using pip, it is highly recommended to use virtual environments, which isolate the installed packages from the system packages, thus removing the need to use administrator privileges. To create a virtual environment in the .venv directory, use the following command.

$ python -m venv .venv

参考

venv -- creating virtual environments

警告

Note that in some Linux distributions, such as Debian and Ubuntu, this might require an extra installation step as follows.

$ apt-get install python3-venv

Docker

Docker images for Sphinx are published on the Docker Hub. There are two kind of images:

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.

注釈

sphinxdoc/sphinx-latexpdf にはTeXLiveパッケージが含まれています。そのため、イメージは非常に大きくなります(2GB以上!)。

ヒント

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:

$ docker run -it --rm -v /path/to/document:/docs sphinxdoc/sphinx sphinx-quickstart

And you can use the following command to build HTML document:

$ docker run --rm -v /path/to/document:/docs sphinxdoc/sphinx make html

詳細については、docker imagesの README file をお読みください。

ソースからインストール

Git repository のクローンからSphinxを直接インストールすることができます。これは、単に git 経由で直接インストールするか、リポジトリをクローンしてローカルのクローンからインストールすることで行うことができます。

$ git clone https://github.com/sphinx-doc/sphinx
$ cd sphinx
$ pip install .
$ pip install git+https://github.com/sphinx-doc/sphinx

Gitリポジトリのスナップショットを tar.gz または zip フォーマットでダウンロードすることもできる。ダウンロードして解凍すると、上記のように pip を使用してインストールできます。