Miro Iliaš
Miro Iliaš

Reputation: 428

Could not import extension ... SphinxDirective

I am trying to test the sphinx extension TODO from https://sphinx.readthedocs.io/en/master/development/tutorials/todo.html#writing-the-extension

However, this import "from docutils.parsers.rst import SphinxDirective" does not work, giving "Extension error: Could not import extension todo (exception: No module named SphinxDirective) "

I tried python2 and python3 , and readthedocs environment.

the code is here, https://www.sphinx-doc.org/en/master/development/tutorials/todo.html#writing-the-extension

ReadTheDocs gives this message:

Running Sphinx v1.8.5
loading translations [en]... done

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/sphinx/registry.py", line 472, in load_extension
    mod = __import__(extname, None, None, ['setup'])
  File "/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/checkouts/latest/docs/todo.py", line 6, in <module>
    from docutils.parsers.rst import SphinxDirective
ImportError: cannot import name 'SphinxDirective' from 'docutils.parsers.rst' (/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/docutils/parsers/rst/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/sphinx/cmd/build.py", line 303, in build_main
    args.tags, args.verbosity, args.jobs, args.keep_going)
  File "/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 228, in __init__
    self.setup_extension(extension)
  File "/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 449, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/sphinx/registry.py", line 475, in load_extension
    raise ExtensionError(__('Could not import extension %s') % extname, err)
sphinx.errors.ExtensionError: Could not import extension todo (exception: cannot import name 'SphinxDirective' from 'docutils.parsers.rst' (/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/docutils/parsers/rst/__init__.py))

Extension error:
Could not import extension todo (exception: cannot import name 'SphinxDirective' from 'docutils.parsers.rst' (/home/docs/checkouts/readthedocs.org/user_builds/demo-sphinx-extensions-for-dirac/envs/latest/lib/python3.7/site-packages/docutils/parsers/rst/__init__.py))

Upvotes: 2

Views: 6937

Answers (1)

Miro Iliaš
Miro Iliaš

Reputation: 428

Well,

one has to use proper files from the tutorial, https://www.sphinx-doc.org/en/master/development/tutorials/todo.html , together with all installed packages.

This is ensured on the ReadTheDocs portal, where the extension buildup works well.

PS: Files and links are https://github.com/miroi/demo-sphinx-extensions-for-DIRAC

Upvotes: 3

Related Questions