在尝试使用 sphinx matlab 域时,我无法让 MWE 工作,extensions pypi site 上提供
总是出现无法导入模块
错误。我猜想,扩展类型会从 m 代码生成伪模块,但据我所知,我实际上无法弄清楚这种机制是如何工作的。
目录结构如下所示
root
|--test_data
| |--MyHandleClass.m
|
|--doc
|--------conf.py
|--------Makefile
|--------index.rst
文件 MyHandleClass.m
和 index.rst
包含 package site 上给出的示例代码。 conf.py
像这样开始
import sys, os
sys.path.append(os.path.abspath('.'))
sys.path.append(os.path.abspath('./test_data'))
# -- General configuration -----------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
"sphinxcontrib.matlab",
"sphinx.ext.autosummary",
"sphinx.ext.autodoc"]
autodoc_default_flags = ['members','show-inheritance','undoc-members']
autoclass_content = 'both'
mathjax_path = 'http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=default'
# The suffix of source filenames.
source_suffix = '.rst'
# The encoding of source files.
#source_encoding = 'utf-8'
# The master toctree document.
master_doc = 'index'
错误消息
WARNING: autodoc: failed to import module u'test_data'; the following exception was raised:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\sphinx\ext\autodoc.py", line 335, in import_object
__import__(self.modname)
ImportError: No module named test_data
E:\ME\doc\index.rst:13: WARNING: don't know which module to import for autodocumenting u'MyHandleClass' (try placing a "module" or "currentmodule" directive in the document, or giving an explicit module name)
在改变这个和那个之后,也许有人有线索?
最佳答案
感谢您尝试 matlabdomain sphinxcontrib 扩展。为了使用 Sphinx 记录 MATLAB m 文件,您需要在 conf.py
中添加 matlab_src_dir
,如 Configuration 中所述。文档的部分。这是因为 Python 解释器无法导入 MATLAB m 文件。因此,您不应该不要将 MATLAB 根目录添加到 Python sys.path
中,否则您将收到收到的错误。而是将 matlab_src_dir
设置为包含您要记录的 MATLAB 项目文件夹的路径。
鉴于您的文件结构,为了记录 test_data
,请使用具有以下内容的 conf.py
:
import os
# NOTE: don't add MATLAB m-files to `sys.path`
#sys.path.insert(0, os.path.abspath('.'))
# instead add them to `matlab_src_dir
matlab_src_dir = os.path.abspath('..') # MATLAB
希望能做到!请随时提出任何更多问题。我很乐意提供帮助!
关于matlab - 使用 matlabdomain 时导入模块失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26520845/