Sphinx matlab documentation error: missing module 'std'
<p>I'm trying to document my MATLAB classes using sphinx. But whenever I want to run <code>make html</code> I get the following error:</p>

<pre><code>% 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
</code></pre>

<p>I'm on ArchLinux and tried the following installation ways, but all result in the same problem:</p>

<p>Try 1:</p>

<pre><code>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
</code></pre>

<p>Try 2:</p>

<pre><code>yaourt -R python-sphinx # (I also removed all dependencies)
sudo pip -U install sphinx
sudo pip -U install -U sphinxcontrib-matlabdomain
</code></pre>

<p>In neither of the cases it worked (always the error from above). In each try I also verified that the <code>std</code> module is there via</p>

<pre><code># 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
</code></pre>

<p>P.S.: my default python has version 3.5.2</p>

<p>Edit 1:</p>

<pre><code>% 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
</code></pre>

<p>The extensions in the sphinx-contrib repository seem to be meant for Python 2. The import rules have changed in Python 3, therefore such errors can occur when Python 3 code is run with a Python 2 interpreter.</p>

<p>The solution is to install Sphinx and all its dependencies for Python 2. Your distribution might have <code>python2-sphinx</code>. On Fedora and Ubuntu the packages <code>python-*</code> are always Python 2 or both, <code>python3-*</code> is the Python 3 package.</p>

<p>On Arch Linux I know that <code>python</code> is symlinked to <code>python3</code>. So there might be additional <code>python2-*</code> packages. Install <code>pip2</code> (because <code>pip</code> is likely to be <code>pip3</code> on Arch Linux) and use that to install Sphinx.</p>

<p>You can find out which interpreter is called by running <code>head -n 1 $(which sphinx-build)</code> and then check the path.</p>

<ul>
<li><code>/usr/bin/python</code>: That is Python 2 on Ubuntu or Fedora, Python 3 on Arch Linux</li>
<li><code>/usr/bin/python3</code>: Definitely Python 3</li>
<li><code>/usr/bin/python2</code>: Definitely Python 2</li>
<li><code>/usr/bin/env python</code>: Similar to the others.</li>
</ul>

<p>Otherwise one could do a <code>print</code> of the Python version inside of the <code>conf.py</code> such that it is printed explicitly.</p>

python matlab python-3.x python-sphinx