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

89.4k views Asked by At

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
15

There are 15 answers

4
Anthon On

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.

0
Varun kadekar On

Try conda install ruamel.yaml ... pip didnt work for me

0
Innanov On

Go to anaconda3\lib\site-packages\rpcq_base.py and change line #22 :

from ruamel import yaml

to

from ruamel_yaml as yaml
0
Alexis Lucattini On

For me this was a conda/pip error. I'd tried to install (cwltool in my case) through pip.
It completed successfully, but then running any command gave me the error like above.

ImportError: No module named ruamel.yaml.

It turned out that the pip binary wasn't part of my conda env and was installing cwltool into a completely separate location.

To resolve the issue I completed the following:

conda activate <env I want to install cwltool into>

conda install -y pip

# Run 'rehash' now if you're using zsh to ensure you're using the right pip

pip install cwltool

cwltool -h
0
JAG2024 On

This might not be a popular answer, but it finally helped me after many hours of troubleshooting:

  1. Uninstall conda (I used this stack overflow solution) and also rm -rf miniconda3 in my home directory, fwiw.
  2. Reinstalled conda using data camp's tutorial.

No other solutions worked for me after lots of head banging.

0
spacetyper On

The above answer didn't work for me. I had to do a fresh install of the core conda components as described in the conda docs here. Copy and pasted below:

Issue: My conda is broken and I want to fix it without blowing away the current installation I am getting a conda error and want to reinstall Miniconda to fix it but when I try, it gives me the error that Miniconda (or Anaconda) is already installed and will not let me continue. I want to force the installation.

Resolution: Install Miniconda using the -f (force) option Download and install the appropriate Miniconda for your computer operating system from the Miniconda download page using the force or -f option as shown:

bash Miniconda3-latest-MacOSX-x86_64.sh -f

NOTE: Substitute the appropriate filename and version for your operating system.

NOTE: Be sure that you install to same install location as your existing install so it overwrites the core conda files and does not install a duplicate in a new folder.

0
arunppsg On

To add to what @user612161 has said, go to the directory of parent module (dateparser in this case) requiring ruamel.yaml:

cd anaconda2/lib/python2.7/site-packages/dateparser

and change all occurrences of ruamel.yaml into ruamel_yaml by the following command (Linux):

find . -name '*.py' | xargs sed -i 's/ruamel.yaml/ruamel_yaml/g'
0
Charles Xu On

This is my problem and solution.

Problem:

import ruamel_yaml as yaml
ModuleNotFoundError: No module named 'ruamel_yaml'

Solution: 1. Install ruamel.yaml through pip.

pip install ruamel.yaml 
  1. Update the calling code from ruamel_yaml to ruamel.yaml.

May not directly relation this problme. But useful if others met with the same problem.

0
Serg Kryvonos On

Try sudo pip install ruamel_yaml

0
Nicholas Luo On

Try pip install ruamel.yaml

It works for me.

2
FDeery On

I was trying to link Bloomberg to Python

pip install --index-url=https://bcms.bloomberg.com/pip/simple blpapi pip install xbbg

so far, so good.... then I tried to import a module from the package xbbg: from xbbg import blp and I was faced with an error, it couldn't find "ruamel.yaml" within the "param.py" within the xbbg module

When I dug into the folder C:/Anaconda3/Lib/site-packages I could see that there was a folder there called ruamel_yaml so I went back to the param.py file and edited ruamel.yaml to be ruamel_yaml as suggested in other posts.

"from xbbg import blp" now worked and I'm able to take data directly from Bloomberg into Python now. Problem solved.

I have a feeling that this issue is being caused by downloading different versions at different times as I've found the learning curve to get setup on Python difficult with many false starts. I was tearing my hair out a bit because I just got Python up and running linked to Bloomberg on my work pc but when I tried to link Bloomberg up to Python on my laptop it kept getting stuck with the "ruamel" issue. The version of Python on my laptop is much older than the version on my work pc. What makes me think that its a version issue is that I did not have to edit ruamel.yaml to be ruamel_yaml in order for me to link Python and BB.

These are just ideas, I'm too inexperienced at this stage to offer much more than to share what happened.

0
Julian Wise On

The quick and easy is to ignore the previously installed version in an upgrade

 pip install --ignore-installed ruamel_yaml==0.17.4
0
dave campbell On

this worked for me:

pip install --upgrade ruamel.yaml --ignore-installed ruamel.yaml

from an answer in matsci.org https://matsci.org/t/modulenotfounderror-no-module-named-ruamel/36183

0
Panoptik On

For python3 use

pip3 install ruamel_yaml

if pip3 not installed try at first

sudo apt install python3-pip 
0
user612161 On

I went into this file:

/anaconda2/lib/python2.7/site-packages/dateparser/utils/__init__.py

edited this line:

import ruamel.yaml as yaml 

to read

import ruamel_yaml as yaml 

Changing the dot to an underscore worked for me.... I hope it works for you.