Sphinx matlab documentation error: missing module 'std'

Sphinx matlab documentation error: missing module 'std'

我正在尝试使用 sphinx 记录我的 MATLAB 类。但是每当我想 运行 make html 时,我都会收到以下错误:

% make html
sphinx-build -b html -d _build/doctrees   . _build/html
Running Sphinx v1.4.6

Extension error:
Could not import extension sphinxcontrib.matlab (exception: No module named 'std')
make: *** [Makefile:53: html] Error 1

我在 ArchLinux 上尝试了以下安装方式,但都出现了同样的问题:

尝试 1:

yaourt -S python-sphinx # (was already installed by default, just to show that the package came from arch repo)
sudo pip install -U sphinxcontrib-matlabdomain

尝试 2:

yaourt -R python-sphinx # (I also removed all dependencies)
sudo pip -U install sphinx
sudo pip -U install -U sphinxcontrib-matlabdomain

在这两种情况下它都不起作用(总是上面的错误)。在每次尝试中,我还通过

验证了 std 模块是否存在
# ll /usr/lib/python3.5/site-packages/sphinxcontrib*
-rw-r--r-- 1 root root 326 Sep 28 11:02 /usr/lib/python3.5/site-packages/sphinxcontrib_blockdiag-1.5.5-py2.7-nspkg.pth
-rw-r--r-- 1 root root 326 Sep 28 11:00 /usr/lib/python3.5/site-packages/sphinxcontrib_matlabdomain-0.2.7-py3.5-nspkg.pth

/usr/lib/python3.5/site-packages/sphinxcontrib:
total 152
-rw-r--r-- 1 root root 11457 Sep 28 11:02 blockdiag.py
-rw-r--r-- 1 root root 37815 Jun 20  2015 mat_documenters.py
-rw-r--r-- 1 root root 27529 Oct  7  2014 matlab.py
-rw-r--r-- 1 root root 46088 Jun 20  2015 mat_types.py
drwxr-xr-x 1 root root   126 Sep 28 11:03 __pycache__
-rw-r--r-- 1 root root 22278 Feb  7  2014 std.py

/usr/lib/python3.5/site-packages/sphinxcontrib_blockdiag-1.5.5.dist-info:
total 32
-rw-r--r-- 1 root root 1033 Sep 28 11:02 DESCRIPTION.rst
-rw-r--r-- 1 root root    4 Sep 28 11:03 INSTALLER
-rw-r--r-- 1 root root 2127 Sep 28 11:02 METADATA
-rw-r--r-- 1 root root 1193 Sep 28 11:02 metadata.json
-rw-r--r-- 1 root root   14 Sep 28 11:02 namespace_packages.txt
-rw-r--r-- 1 root root 1054 Sep 28 11:03 RECORD
-rw-r--r-- 1 root root   14 Sep 28 11:02 top_level.txt
-rw-r--r-- 1 root root  110 Sep 28 11:02 WHEEL

/usr/lib/python3.5/site-packages/sphinxcontrib_matlabdomain-0.2.7-py3.5.egg-info:
total 40
-rw-r--r-- 1 root root    1 Sep 28 11:00 dependency_links.txt
-rw-r--r-- 1 root root  487 Sep 28 11:00 installed-files.txt
-rw-r--r-- 1 root root   14 Sep 28 11:00 namespace_packages.txt
-rw-r--r-- 1 root root    1 Jun 20  2015 not-zip-safe
-rw-r--r-- 1 root root 8547 Sep 28 11:00 PKG-INFO
-rw-r--r-- 1 root root   28 Sep 28 11:00 requires.txt
-rw-r--r-- 1 root root  549 Sep 28 11:00 SOURCES.txt
-rw-r--r-- 1 root root   14 Sep 28 11:00 top_level.txt

P.S.: 我的默认 python 版本是 3.5.2

编辑 1:

% head $(which sphinx-build)
#!/usr/bin/python

# -*- coding: utf-8 -*-
import re
import sys

from sphinx import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
% which sphinx-build
/usr/bin/sphinx-build
% sphinx-build --version
Sphinx (sphinx-build) 1.4.6
% python --version
Python 3.5.2
% /usr/bin/python --version
Python 3.5.2

sphinx-contrib 存储库中的扩展似乎是针对 Python 2 的。导入规则在 Python 3 中已更改,因此当 Python 3 时可能会出现此类错误代码是 运行 和 Python 2 解释器。

解决方案是为 Python 2 安装 Sphinx 及其所有依赖项。您的发行版可能有 python2-sphinx。在 Fedora 和 Ubuntu 上,包 python-* 总是 Python 2 或两者,python3-* 是 Python 3 包。

在 Arch Linux 上,我知道 python 是符号链接到 python3。所以可能会有额外的 python2-* 包。安装 pip2(因为 pip 在 Arch Linux 上很可能是 pip3)并使用它来安装 Sphinx。

你可以找出运行ninghead -n 1 $(which sphinx-build)调用的是哪个解释器,然后查看路径

  • /usr/bin/python:即 Python 2 on Ubuntu or Fedora,Python 3 on Arch Linux
  • /usr/bin/python3:绝对Python 3
  • /usr/bin/python2:绝对Python 2
  • /usr/bin/env python: 和其他的差不多。

否则,可以在 conf.py 中使用 Python 版本的 print,以便明确打印。

sphinxcontrib-matlabdomain 的最新版本 (>=0.2.11) 同时支持 Python 2 和 3。我认为这应该可以解决您看到的问题。