Conda 'ImportError: No module named ruamel.yaml.comments'

Nipun Garg picture Nipun Garg · Dec 29, 2016 · Viewed 41.9k times · Source

Conda gives error when I run any command with it.

Traceback (most recent call last):
  File "/usr/local/bin/conda", line 7, in <module>
    from conda.cli.main import main
  File "/usr/local/lib/python2.7/dist-packages/conda/cli/__init__.py", line 8, in <module>
    from .main import main  # NOQA
  File "/usr/local/lib/python2.7/dist-packages/conda/cli/main.py", line 46, in <module>
    from ..base.context import context
  File "/usr/local/lib/python2.7/dist-packages/conda/base/context.py", line 18, in <module>
    from ..common.configuration import (Configuration, MapParameter, PrimitiveParameter,
  File "/usr/local/lib/python2.7/dist-packages/conda/common/configuration.py", line 40, in <module>
    from ruamel.yaml.comments import CommentedSeq, CommentedMap  # pragma: no cover
ImportError: No module named ruamel.yaml.comments

Answer

Anthon picture Anthon · Dec 29, 2016

The module ruamel.yaml.comments will normally be loaded from site-packages/ruamel/yaml/comments.py, and not from site-packages/ruamel_yaml/comments.py

Conda seems to have problems with properly supporting namespaces (ruamel.) which I can only attribute to not (yet) being fully pip compatible. That although "namespaces are a honking good idea", and package namespaces have been around for many years.

Assuming you can extend "conda" installations with pip you could try to do a normal install of ruamel.yaml with:

 pip install ruamel_yaml==0.11.14

I would not normally recommend such an old version, but that is more likely to work in combination with the version conda uses itself internally.

The alternative would be to switch to using python and pip without conda, that way you can just use the latest version of software from PyPI.