44

This was our processes of installing Sphinx.

> choco install python -y -f
> pip install sphinx

We know that sphinx installed because of the following output.

> pip show sphinx
---
Metadata-Version: 2.0
Name: Sphinx
Version: 1.4.3
Summary: Python documentation generator
Home-page: http://sphinx-doc.org/
Author: Georg Brandl
Author-email: georg@python.org
License: BSD
Location: c:\programdata\chocolatey\lib\python3\tools\lib\site-packages

We also added its install location to our PATH.

c:\programdata\chocolatey\lib\python3\tools\lib\site-packages

Even so, running sphinx-build does not work.

'sphinx-build' is not recognized as an internal or external command,
operable program or batch file.
barryhunter
  • 20,886
  • 3
  • 30
  • 43
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467

8 Answers8

34

I stumbled into that problem too when installed Sphinx using pip. The problem was solved using the installation way proposed by official documentation:

For Python 3:

$ apt-get install python3-sphinx

For Python 2:

$ apt-get install python-sphinx
Symon
  • 1,626
  • 1
  • 23
  • 31
  • I'm getting the same error when I install sphinx from pip in Ubuntu, via a Jenkins pipeline. The Jenkins pipeline fails with `command was not found`, and then it works on a second attempt - probably a path/environment thing? Locally I use Windows, and Sphinx installation works fine. – H.Scheidl Nov 19 '18 at 08:37
  • 3
    This does not work for Ubuntu 18.04 LTS since apt-get packages an outdated version of sphinx that isn't compatible with one installed by pip... – Thomas Jan 23 '20 at 08:57
  • @H.Scheidl Did you ever find a solution for Jenkins? It works on my machine via docker-compose, but fails in Jenkins. – Marc LaBelle Apr 22 '20 at 18:05
  • Unfortunately, on Ubuntu 22.04, `apt`/`apt-get` installs Sphinx version 4.3.2, whereas the current Sphinx version is 6.1.3. – djvg Feb 10 '23 at 11:07
  • The solution from Makiyu (see below), calling python -m sphinx.cmd.build worked for me in my GitLab pipeline on Ubuntu. – Stefan Jun 15 '23 at 12:40
25

For macOS Mojave:

$ brew install sphinx-doc

upon install brew will notify you to add it to your path, so add the following line to your ~/.bash_profile:

export PATH="/usr/local/opt/sphinx-doc/bin:$PATH"

after that you can run the sphinx-build command (you can verify this by for example checking the version)

$ sphinx-build --version
sphinx-build 2.0.1
Kim Paulissen
  • 578
  • 5
  • 5
9

An alternative way to invoke sphinx-build is to explicitly load Sphinx's build module.

For Sphinx v1.7+:

python -m sphinx.cmd.build

Here's an example for that I did with my documentation:

$ python3 -m sphinx.cmd.build -b html docs/ docs/build/
Running Sphinx v4.0.2
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] api                                                                      
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                     
generating indices... genindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.

The HTML pages are in docs/build.

I got the idea of trying to load the module with this answer, originally for sphinx-quickstart.
Suprisingly, I succeeded.

Makiyu
  • 411
  • 3
  • 10
4

We added the wrong directory to the path.

Wrong:

c:\programdata\chocolatey\lib\python3\tools\lib\site-packages

Right:

c:\programdata\chocolatey\lib\python3\tools\Scripts
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
4

For Windows:

Setting python path in make.bat fixed the problem for me:

set SPHINXBUILD="D:\Python3\Scripts\sphinx-build.exe"
Javier C.
  • 7,859
  • 5
  • 41
  • 53
1

For macports adding

export PATH="/opt/local/Library/Frameworks/Python.framework/Versions/3.7/bin:$PATH"

to $HOME/.bash_profile fixed the issue

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
1

I fixed the problem by just installing from pip and restarting the terminal.

Harshil Mehta
  • 86
  • 1
  • 4
0

The problem may be related to the Python interpreter. At some point in time, some distributions removed

 /usr/bin/python

sphinx-build relied on that. So, may be

 sudo ln -s /usr/bin/python2.7 /usr/bin/python

may help. But, this needs to be handled with care, since the PATH points to this directory and some scripts/programs may then access Python2.7 instead of maybe Python3 from some other place.

Frank-Rene Schäfer
  • 3,182
  • 27
  • 51