0

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.

Shivam Singh
  • 87
  • 2
  • 11
  • 1
    I think you need `sys.path.insert(0, os.path.abspath('../..'))`. – mzjn Mar 29 '22 at 05:58
  • Thanks a lot! It worked. But can you share the intuition behind it. I used .. because all python modules are present just a folder above the conf.py. Why ('../..') works? It will help me with future projects. – Shivam Singh Mar 29 '22 at 08:35
  • The folder that contains "Utils" must be in `sys.path`. Many similar questions have already been asked, for example https://stackoverflow.com/q/50230797/407651 – mzjn Mar 29 '22 at 08:48

0 Answers0