Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import module to Sphinx

import myModule as myModule

with this code works import and I can make my doc

import myPackage.myModule as myModule

with this I get

"No module named myPackage.myModule"

Doesn't matter if this file exist in root directory or in myPackage directory.

In RST-File I have not mentioned about myModule, I want to document other file that just import this module.

like image 786
Meloun Avatar asked Dec 27 '22 07:12

Meloun


1 Answers

Sphinx needs to be able to import your code, to generate documentation for classes and functions. You probably need to add your project's root folder to sys.path in Sphinx. You can do this from the Sphinx conf.py file:

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

Replace '..' with the relative path to the project root.

like image 136
Alex Morega Avatar answered Dec 31 '22 13:12

Alex Morega