ImportError for my code on Readthedocs

大城市里の小女人 提交于 2019-12-05 09:45:25

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.

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