7

我正在尝试将我的 Sphinx 文档与ReadtheDocs链接起来。我可以在本地构建文档,但是当我尝试让ReadtheDocs自动生成文档时,我收到以下错误:

狮身人面像标准错误

Making output directory...

Exception occurred:
  File "/var/build/user_builds/mousedb/checkouts/latest/Docs/source/conf.py", line 25, in <module>
    from mousedb import settings
ImportError: No module named mousedb
The full traceback has been saved in /tmp/sphinx-err-n_8fkR.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
Either send bugs to the mailing list at <http://groups.google.com/group/sphinx-dev/>,
or report them in the tracker at <http://bitbucket.org/birkenfeld/sphinx/issues/>. Thanks!

我的项目名称是 mousedb。我不明白为什么我在自动构建中收到此导入错误,但在本地却没有。

更新

根据评论,我认为这是将我的设置文件导入同级Docs目录的问题。settings.py我应该根据and的位置进行相对导入,而不是进行绝对导入(就像我一直在做的那样)conf.py

我想将我的设置文件导入到我conf.py的目录结构中:

-mousedb
--settings.py
-Docs
--source
---conf.py
--build
4

1 回答 1

8

您最初谈到“我的代码的本地绝对路径”,现在谈到设置代码的相对路径。这可能意味着您没有使用setup.py文件,也没有使用 virtualenv。

在与 和 相同的目录中Docs/mousedb/添加setup.py

from setuptools import setup

setup(name='mousedb',
      version='0.1',
      description="My sample package",
      long_description="",
      author='TODO',
      author_email='todo@example.org',
      license='TODO',
      packages=['mousedb'],
      zip_safe=False,
      install_requires=[
          'Django',
          # 'Sphinx',
          # ^^^ Not sure if this is needed on readthedocs.org
          # 'something else?',
          ],
      )

在提交/推送/无论这个文件之后,您可以转到您的项目的 readthedocs 设置。启用“使用 virtualenv”设置。这将“使用 setup.py install 在 vi​​rtualenv 中安装您的项目”。

最终结果是 readthedocs 所做的所有与 python 相关的事情都将包含您的项目sys.path

The probable cause of your problems is that you run sphinx from within your "root" directory on your local system, where python magically finds the mousedb/ package in your current directory. But readthedocs apparently runs it from within the Docs/ directory and thus cannot find mousedb.

于 2012-11-18T17:20:15.923 回答