[英]Changing the sys.path for read the docs
I am documenting my pyramid project locally with sphinx. 我正在用狮身人面像在本地记录我的金字塔项目。 Locally autodoc
works fine and the documentation looks the way I want it. 在本地autodoc
可以正常工作,并且文档看起来像我想要的样子。
But if I am using read the docs I get the following error for each use of the autodoc feature: 但是,如果我正在阅读文档,则每次使用autodoc功能时都会遇到以下错误:
/home/docs/checkouts/readthedocs.org/user_builds/buchungssystem/checkouts/latest/docs/source/02database/02models.rst:8: 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/readthedocs.org/user_builds/buchungssystem/envs/latest/local/lib/python2.7/site-packages/sphinx/ext/autodoc.py", line 385, in import_object __import__(self.modname) ImportError: No module named buchungssystem.models.person
My project is structured like this: 我的项目的结构如下:
project
->code
->models
->scripts
->...
->__init__.py
->...
->docs
->conf.py
->documentation
->setup.py
I think that my sys.path is not configured correctly. 我认为我的sys.path配置不正确。 After trying out a lot I am back at sys.path.insert(0, os.path.abspath('.'))
尝试了很多之后,我回到了sys.path.insert(0, os.path.abspath('.'))
in your conf.py
try this 在您的conf.py
试试这个
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. 因为它需要通向Person
类的路径,并且该类是层次结构中的上一步,因此您可以拉出该类的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.