make html期间由于sys.path而出错

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

我正在尝试为软件包构建Sphinx文档,但我不断收到错误消息,可能会需要一些帮助。我的项目目录为bb_lite,代码位于backend文件夹中。

bb_lite
    ├── 1.0\ docs
    ├── 2.0\ data 
    ├── README.md
    └── backend 

这是我的backend文件夹的外观。

├── README.md
├── __init__.py
├── __pycache__
│   └── __init__.cpython-36.pyc
├── archive
│   ├── cont_pca_transform_w_original_func.py
│   └── model_tuner.py
├── automl_pipeline
│   ├── __init__.py
│   ├── flow.py
│   └── input_json.json
├── data_preparation
│   ├── __init__.py
│   ├── cat_multiclass_label_index_encoding.py
│   ├── cross_validator.py
│   ├── data_samplers.py
│   └── train_test_validator

I cdbb_lite文件夹,创建docs文件夹和cddocs。从那里我运行sphinx-quickstart。当它要求分隔源目录和构建目录时,我键入y并按Enter键。当要求输入自动文档扩展名时,我输入y并完成其他操作。我的docs看起来像-

.
├── Makefile
├── build
├── make.bat
└── source
    ├── _static
    ├── _templates
    ├── conf.py
    └── index.rst

一旦完成,我打开里面的conf.py文件并取消对前三行的注释

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

使用docs文件夹作为我的工作目录,运行以下命令

sphinx-apidoc -f -o source/ ../backend/

这给了我

Creating file source/backend.rst.
Creating file source/backend.automl_pipeline.rst.
Creating file source/backend.data_preparation.rst.
Creating file source/backend.explain.rst.
Creating file source/backend.explain.k_limes.rst.
Creating file source/backend.explain.surrogate_models.rst.
Creating file source/backend.feature_extraction.rst.
Creating file source/backend.model_tuner.rst.
Creating file source/backend.parameter_tuning.rst.
Creating file source/backend.profiling.rst.
Creating file source/backend.tests.rst.
Creating file source/backend.utilities.rst.
Creating file source/modules.rst.

最后,我运行make html(从docs目录运行),这使我出现以下错误-运行Sphinx v1.7.4

making output directory...
loading pickled environment... not yet created
loading intersphinx inventory from https://docs.python.org/objects.inv...
intersphinx inventory has moved: https://docs.python.org/objects.inv -> https://docs.python.org/3/objects.inv
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 14 source files that are out of date
updating environment: 14 added, 0 changed, 0 removed
reading sources... [100%] modules                                                                                                                                                                           
WARNING: autodoc: failed to import module 'backend.utilities'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.automl_pipeline.flow'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.automl_pipeline'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.data_preparation.cat_multiclass_label_index_encoding'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.data_preparation.cross_validator'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.data_preparation.data_samplers'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.data_preparation'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.explain'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.explain.k_limes'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.explain.surrogate_models'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.feature_extraction.cat_frequency_transformer'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.feature_extraction.cont_bulk_interactions'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.feature_extraction.cont_pca_transform'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.feature_extraction.naming_constants'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.feature_extraction'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner.cross_validator'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner.hyperparam_bounds'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner.model_specs'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner.model_tuner_class'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner.model_tuner_pipeline'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner.train_test_validator'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.model_tuner'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.parameter_tuning'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.profiling'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.tests'; the following exception was raised:
No module named 'backend'
WARNING: autodoc: failed to import module 'backend.utilities'; the following exception was raised:
No module named 'backend'
looking for now-outdated files... none found
pickling environment... done
checking consistency... /Users/shubhamgandhi/Desktop/bb_lite/docs/source/modules.rst: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [100%] modules                                                                                                                                                                            
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 28 warnings.

The HTML pages are in build/html.

我不知道我要去哪里错了。我关注了一些文档和博客,但无所适从。当我在index.html中打开docs/build/html时,它没有任何文档。

知道我要去哪里错了吗?

python python-sphinx
1个回答
1
投票

backend目录上方的目录必须添加到sys.path

如果bb_litebackenddocs的父目录,则docs/conf.py中需要以下内容:

sys.path.insert(0, os.path.abspath('..'))
© www.soinside.com 2019 - 2024. All rights reserved.