在尝试使用sphinx matlab域时,我无法让MWE工作,extensions pypi site
始终存在此Can't import module
错误。我猜,扩展类型是从m代码生成伪模块,但最多知道我实际上无法弄清楚,这种机制是如何工作的。
dir结构看起来像这样
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)
改变了这一点后,也许有人在那里有线索?
答案 0 :(得分:2)
感谢您尝试使用matlabdomain sphinxcontrib扩展程序。为了使用Sphinx记录MATLAB m文件,您需要在matlab_src_dir
中添加conf.py
,如文档的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
希望能做到!请随时再提问。我很乐意提供帮助!