Boggy Boggy - 9 months ago 79
Python Question

Changing the sys.path for read the docs

I am documenting my pyramid project locally with sphinx. Locally

works fine and the documentation looks the way I want it.

But if I am using read the docs I get the following error for each use of the autodoc feature:

/home/docs/checkouts/ WARNING: autodoc: failed to import class u'Person' from module u'buchungssystem.models.person'; the following exception was raised:
Traceback (most recent call last):
File "/home/docs/checkouts/", line 385, in import_object
ImportError: No module named buchungssystem.models.person

My project is structured like this:


I think that my sys.path is not configured correctly. After trying out a lot I am back at
sys.path.insert(0, os.path.abspath('.'))

Answer Source

in your try this

sys.path.insert(0, os.path.join(os.path.dirname((os.path.abspath('.')), 'code', 'models')

because it requires path to the Person class and that class is one step up in your hierarchy and the you can pull the path of that class.