简体   繁体   中英

The 'sphinx-build' command was not found.

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.

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

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

For Windows:

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

set SPHINXBUILD="D:\Python3\Scripts\sphinx-build.exe"

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

我通过从pip安装并重新启动终端来解决这个问题。

For macports adding

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

to $HOME/.bash_profile fixed the issue

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM