Не удалось создать документацию sphinx из-за сбоя модуля импорта - PullRequest
0 голосов
/ 08 января 2020

Я пытаюсь создать документацию через Sphinx, но он не может импортировать модуль, но когда я пытаюсь импортировать его через python, интерактивная оболочка работает нормально.

Running Sphinx v1.6.7
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 1 changed, 0 removed
reading sources... [100%] gnmi_manager                                                                                                                                                                          
/home/lab/dev/gNMI-API/docs/gnmi_manager.rst:4: WARNING: autodoc: failed to import module 'gnmi_manager'; the following exception was raised:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/sphinx/ext/autodoc.py", line 658, in import_object
    __import__(self.modname)
  File "/home/lab/dev/gNMI-API/gnmi_manager.py", line 1, in <module>
    import grpc
  File "/home/lab/dev/gNMI-API/venv/lib/python3.7/site-packages/grpc/__init__.py", line 23, in <module>
    from grpc._cython import cygrpc as _cygrpc
ImportError: cannot import name 'cygrpc'
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] modules                                                                                                                                                                                
generating indices... genindex py-modindex
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, 1 warning.

Build finished. The HTML pages are in _build/html.

Python 3.6.9 (default, Nov  7 2019, 10:44:02) 
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from grpc._cython import cygrpc as _cygrpc
>>> 

Есть ли способ использовать виртуальный env при запуске команды make html из sphinx?
У меня установлена ​​библиотека grpcio как в venv, так и глобально для python3 .6, python2 .7. Могу ли я узнать, что использует python sphinx make html?

conf.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# gnmi-api documentation build configuration file, created by
# sphinx-quickstart on Fri Jan  3 10:46:37 2020.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
from os.path import abspath, dirname, join 
import sys
sys.path.insert(1, dirname(dirname(abspath(__file__))))
...