Setuptools command crashes under Python 3.3

Nikolaus Rath avatarNikolaus Rath created an issue

Consider this minimal project:

$ md sphinx; cd sphinx
$ md rst
$ cat >
master_doc = 'about'

$ cat >
from setuptools import setup, find_packages
    name = "HelloWorld",
    version = "0.1",
    packages = find_packages(),

$ cat > about.rst

Hello, world!

When running with sphinx-build . doc, it works just fine. However, when running with setuptools, it crashes:

$ python3.3 -m pdb build_sphinx -a -E
> /home/nikratio/tmp/sphinx2/<module>()
-> from setuptools import setup, find_packages
(Pdb) c
running build_sphinx
Running Sphinx v1.2b1
building [html]: all source files
updating environment: 1 added, 0 changed, 0 removed
Traceback (most recent call last):                                                                           
  File "/usr/lib/python3.3/", line 1658, in main
  File "/usr/lib/python3.3/", line 1539, in _runscript
  File "/usr/lib/python3.3/", line 405, in run
    exec(cmd, globals, locals)
  File "<string>", line 1, in <module>
  File "/home/nikratio/tmp/sphinx2/", line 3, in <module>
    from setuptools import setup, find_packages
  File "/usr/lib/python3.3/distutils/", line 148, in setup
  File "/usr/lib/python3.3/distutils/", line 917, in run_commands
  File "/usr/lib/python3.3/distutils/", line 936, in run_command
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/", line 143, in run
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/", line 207, in build
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/builders/", line 174, in build_all, summary='all source files', method='all')
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/builders/", line 231, in build
    purple, length):
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/builders/", line 131, in status_iterator
    for item in iterable:
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/", line 458, in update_generator
    self.read_doc(docname, app=app)
  File "/home/nikratio/.local/lib/python3.3/site-packages/sphinx/", line 601, in read_doc
    pub.set_components(None, 'restructuredtext', None)
  File "/home/nikratio/.local/lib/python3.3/site-packages/docutils/", line 96, in set_components
  File "/home/nikratio/.local/lib/python3.3/site-packages/docutils/readers/", line 63, in set_parser
    parser_class = parsers.get_parser_class(parser_name)
  File "/home/nikratio/.local/lib/python3.3/site-packages/docutils/parsers/", line 53, in get_parser_class
    return module.Parser
AttributeError: 'module' object has no attribute 'Parser'
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /home/nikratio/.local/lib/python3.3/site-packages/docutils/parsers/
-> return module.Parser
(Pdb) p module
<module 'rst' (namespace)>
(Pdb) p module.__path__

Removing the rst directory fixes the problem. However, this is rather unfortunate as rst often holds the documentation sources.

I suspect this is related to

Comments (11)

  1. Nikolaus Rath

    A second ingredient for this to happen is PEP 420 (implicit namespaces). Somehow the rst directory ends up creating an implicit namespace. This is why it still works fine in Python 3.2.

  2. Nikolaus Rath

    Here's a monkeypatch for people who want to temporarily work around the issue:

    def fix_docutils():
        '''Work around'''
        import docutils.parsers 
        from docutils.parsers import rst
        old_getclass = docutils.parsers.get_parser_class
        # Check if bug is there
        except AttributeError:
        def get_parser_class(parser_name):
            """Return the Parser class from the `parser_name` module."""
            if parser_name in ('rst', 'restructuredtext'):
                return rst.Parser
                return old_getclass(parser_name)
        docutils.parsers.get_parser_class = get_parser_class
        assert docutils.parsers.get_parser_class('rst') is rst.Parser
  3. Takayuki Shimizukawa

    Sorry, I couldn't reproduce the issue.

    Python 3.3.1
    setuptools 0.9.7


    Python 3.3.1
    setuptools 0.9.7
  4. Georg Brandl

    Hmm, I can't reproduce with docutils 0.11 (but with 0.10). In any case, it looks like and the documentation root are in the same directory, which is an uncommon setup, so I wouldn't worry about it too much.

  5. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.