4

I am trying to use sphinx to run an autodoc. My project structure like this:

enter image description here

Where the python files are reading from input/input.xlsx. My conf.py looks like:

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

extensions = ['sphinx.ext.autodoc']

I run the ./docs/sphinx-apidoc -o ./source ../ where it creates a:

module.rst

and:

My_Project.rst

inside the ./docs/source.

My issue is that when I build the make html, it gives me errors like:

FileNotFoundError: [Errno 2] No such file or directory: './input'

However, as I have set in conf.py, it should logically go two levels high and one level down to /input folder.

../../input

Appreciate any ideas.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Adrian
  • 213
  • 4
  • 9
  • 1
    @bad_coder. Yes, I did that too. But that totally screwed the code and caused new errors since the other files are located in `../../` relative path. Finally I figured out something that worked for me. But before I need to clarify something, in one of files in `../../` the code is reading the excel file from this path `./input/input.xlsx`. Bellow code resolved my issue: ```directory_path = os.path.dirname(os.path.abspath(__file__)) new_path = os.path.join(directory_path, "input.xlsx")``` – Adrian Feb 12 '20 at 06:10

1 Answers1

2

Finally I figured out something that worked for me. Beforehand, I need to clarify something: in one of python files located in ../../ from my source directory, the code is reading an excel file from this path ./input/input.xlsx. I figured out that defining a hard coded path is the source of this issue. So I fixed it with following code:

directory_path = os.path.dirname(os.path.abspath(__file__)) 
new_path = os.path.join(directory_path, "input.xlsx")
Adrian
  • 213
  • 4
  • 9