ImportError for my code on Readthedocs

倖福魔咒の 提交于 2019-12-07 02:28:33

问题


I am trying to link my sphinx documentation with read the docs. I can build the documentation locally but when i try to have read the docs automatically generate the documentation i get the following error:

Sphinx Standard Error

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!

My project name is mousedb. I dont understand why i get this import error in the auto-build but not locally.

Update

Based on the comments i think that this is an issue for importing my settings file into a sibling Docs directory. Rather than doing an absolute import (as i had been doing) I should be doing a relative import based on the location of settings.py and conf.py

I want to import my settings file into my conf.py with the following directory structure:

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

回答1:


You originally talked about a "local absolute path to my code" and now about setting up relative paths to your code. This probably means you're not using a setup.py file and also not a virtualenv.

In the same directory as Docs/ and mousedb/, add a 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?',
          ],
      )

After committing/pushing/whatever this file, you can go to your readthedocs settings for your project. Enable the "use virtualenv" setting. This will "nstall your project inside a virtualenv using setup.py install".

The end result is that everything python-related that readthedocs does will have your project in it's 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.



来源:https://stackoverflow.com/questions/13372068/importerror-for-my-code-on-readthedocs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!