1 year ago

#346393

test-img

Shivam Singh

Sphinx-autodoc Error: Failed to import module. A very basic structure but not able to generate documentation

So I have been working on this for two days but not able to solve the issue. I have a very basic file structure.

Utils
|
├───docs   
│   │
│   ├───build
│   └───conf.py
│       index.rst
│       modules.rst
│       stack.rst
│       _static
│       _templates
|       make.bat
|       Makefile
|
└───__init__.py
    fun1.py
    fun2.py

Just for clear reference. There's a util's folder (package) that contains init.py file, two modules i.e. fun1 and fun2 and a docs folder which in turn contains all sphinx documentation.

docs folder have build folder for html files and rest other files are without the source folder. I also tried by creating separate directories i.e. build and source but it also did not helped.

It only generates the name of the modules. But there's no documentation of them.

Utils.fun1 module Utils.fun2 module

In terminal it shows:

WARNING: autodoc: failed to import module 'fun1' from module 'Utils'; the following exception was raised: No module named 'Utils'

WARNING: autodoc: failed to import module 'fun2' from module 'Utils'; the following exception was raised: No module named 'Utils'

Please help me to solve this issue. It has taken more time than I thought.

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

extensions = ['sphinx.ext.autodoc']

this is the command I'm using - sphinx-apidoc -f -o . ..

If I remove the init.py file from the utils folder everything works. But I cannot delete the init.py file. It is a larger package with more modules but same structure. It might seem absurd because I have created a sample.

python

module

python-sphinx

autodoc

0 Answers

Your Answer

Accepted video resources