Sphinx在读取文档时出现 "模块未找到 "错误,但在本地构建正常。

问题描述 投票:0回答:1

我正试图在Read the Docs上建立我的文档,但我得到了一个可怕的 "模块未找到 "的错误。 如果我发出 make docs 在我的项目的根目录下,一切都能正常构建,所以 "找不到模块 "的错误对我来说非常奇怪,我使用的是PyPackage Cookiecutter模板。

我使用的是PyPackage Cookiecutter模板。下面是我的项目的树的relavent部分。

.
├── docs
│   ├── authors.rst
│   ├── conf.py
│   ├── contributing.rst
│   ├── history.rst
│   ├── index.rst
│   ├── installation.rst
│   ├── make.bat
│   ├── modules.rst
│   ├── readme.rst
│   ├── scattergrid.rst
│   └── usage.rst
├── requirements_dev.txt
├── scattergrid
│   ├── __init__.py
│   ├── cli.py
│   └── scattergrid.py
├── setup.cfg
├── setup.py
├── tests
│   ├── __init__.py
│   └── test_scattergrid.py
└── tox.ini

下面是在同一个项目中成功的本地构建,并发出了: make docs 的根目录下。

Running Sphinx v3.0.4
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 9 source files that are out of date
updating environment: [new config] 9 added, 0 changed, 0 removed
reading sources... [100%] usage
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] usage
generating indices...  genindex py-modindexdone
highlighting module code... [100%] scattergrid.scattergrid
writing additional pages...  searchdone
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 _build/html.
python -c "$BROWSER_PYSCRIPT" docs/_build/html/index.html

下面是 "阅读文档 "中的错误。

Running Sphinx v1.8.5

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/config.py", line 368, in eval_config_file
    execfile_(filename, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/util/pycompat.py", line 150, in execfile_
    exec_(code, _globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/checkouts/latest/docs/conf.py", line 20, in <module>
    import scattergrid
ModuleNotFoundError: No module named 'scattergrid'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/cmd/build.py", line 300, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/application.py", line 201, in __init__
    self.config = Config.read(self.confdir, confoverrides or {}, self.tags)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/config.py", line 203, in read
    namespace = eval_config_file(filename, tags)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/config.py", line 380, in eval_config_file
    raise ConfigError(msg % traceback.format_exc())
sphinx.errors.ConfigError: There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/config.py", line 368, in eval_config_file
    execfile_(filename, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/util/pycompat.py", line 150, in execfile_
    exec_(code, _globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/checkouts/latest/docs/conf.py", line 20, in <module>
    import scattergrid
ModuleNotFoundError: No module named 'scattergrid'


Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/config.py", line 368, in eval_config_file
    execfile_(filename, namespace)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/envs/latest/lib/python3.8/site-packages/sphinx/util/pycompat.py", line 150, in execfile_
    exec_(code, _globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/scattergrid/checkouts/latest/docs/conf.py", line 20, in <module>
    import scattergrid
ModuleNotFoundError: No module named 'scattergrid'

这里是这个错误发生的准确行数,它发生在 docs/conf.py.

import scattergrid
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

这是由cookiecutter模板设置的,你可以看到绝对路径指向docs文件夹的上一层。 如果我不包含以下内容,所有的东西都会建立在阅读文档上。import scattergrid 但当然,我没有任何真正的文档,所以任何帮助将是非常感激的

这里是 docs/scattergrid.rst 构建的cookiecutter模板。

scattergrid package
===================

Submodules
----------

scattergrid.cli module
----------------------

.. automodule:: scattergrid.cli
   :members:
   :undoc-members:
   :show-inheritance:

scattergrid.scattergrid module
------------------------------

.. automodule:: scattergrid.scattergrid
   :members:
   :undoc-members:
   :show-inheritance:


Module contents
---------------

.. automodule:: scattergrid
   :members:
   :undoc-members:
   :show-inheritance: 
python python-sphinx read-the-docs
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.