Sphinx无法导入模块依赖项

时间:2019-09-17 04:36:39

标签: python-sphinx python-3.7 setup.py read-the-docs cookiecutter

编写awscli-bastion的python工具具有由cookiecutter构建的以下目录结构。

.
├── awscli_bastion
│   ├── __init__.py
│   ├── cache.py
│   ├── cli.py
│   ├── credentials.py
│   ├── minimal.py
│   └── sts.py
├── docs
│   ├── Makefile
│   ├── _build
│   ├── ...
│   ├── conf.py
│   ├── ...
├── setup.py
├── .readthedocs.yml
│   ...

其中setup.py包含以下内容:

requirements = [ 'Click>=6.0', 'boto3>=1.5.0', 'awscli>=1.13.0', 'humanize>=0.5.1' ]

其中conf.py包含以下内容:

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

import awscli_bastion

和.readthedocs.yml包含:

# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Build documentation in the docs/ directory with Sphinx
sphinx:
  configuration: docs/conf.py

# Build documentation with MkDocs
#mkdocs:
#  configuration: mkdocs.yml

# Optionally build your docs in additional formats such as PDF and ePub
formats: all

# Optionally set the version of Python and requirements required to build your docs
python:
  version: 3.7

在本地构建sphinx时,所有模块功能都会自动记录下来。

enter image description here

当我在readthedoc.io上构建时,它可以成功导入所有awscli_bastion软件包模块,但是由于导入失败,因此无法自动记录模块功能。

WARNING: autodoc: failed to import module 'cache' from module 'awscli_bastion'; the following exception was raised:
No module named 'dateutil'
WARNING: autodoc: failed to import module 'cli' from module 'awscli_bastion'; the following exception was raised:
No module named 'botocore'
WARNING: autodoc: failed to import module 'credentials' from module 'awscli_bastion'; the following exception was raised:
No module named 'botocore'
WARNING: autodoc: failed to import module 'minimal' from module 'awscli_bastion'; the following exception was raised:
No module named 'boto3'
WARNING: autodoc: failed to import module 'sts' from module 'awscli_bastion'; the following exception was raised:
No module named 'botocore'

https://readthedocs.org/api/v2/build/9667746.txt

这是在https://awscli-bastion.readthedocs.io/en/latest/awscli_bastion.html上呈现的内容

enter image description here

为什么readthedoc.io virtualenv没有安装setup.py中定义的依赖项?

1 个答案:

答案 0 :(得分:0)

好的,我想通过创建包含以下内容的docs/requirements.txt文件来获取要安装的依赖项:

Click>=6.0
boto3>=1.5.0
awscli>=1.13.0
humanize>=0.5.1
docutils>=0.15.2

,然后在.readthedocs.yml

中进行引用
python:
  version: 3.7
  install:
    - requirements: docs/requirements.txt

参考需求的setup.py更为理想,这样我就不必两次定义它们。