Conda 'ImportError: No module named ruamel.yaml.comments'
Asked Answered
S

15

29

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
Sierrasiesser answered 29/12, 2016 at 5:50 Comment(9)
Check if this is helpful: #40734406Streptococcus
@MYGz already tried this.Sierrasiesser
Can you search recursively in your system if ruamel package is there or not?Streptococcus
Are you able to find the folder structure ruamel/yaml/comments.py under the python library folder?Hornback
I found comments.py only at location "home/nipun/anaconda3/pkgs/ruamel_yaml-0.11.14-py35_0/lib/python3.5/site-packages/ruamel_yaml"Sierrasiesser
cd into this path /home/nipun/anaconda3/bin and run ./conda from here. See if it works.Streptococcus
@MYGz Yes it worked. So everytime i want to use conda then i must be in this directory and running command like this? I have installed the ruamel package and when i run conda command now it says "ImportError: No module named pycosat".Sierrasiesser
You did not read the first link I gave you properly. Doing the steps in that link will fix your issue. For now you can do this and check if it's working from any path. Type this on shell export PATH="/home/nipun/anaconda3/bin:$PATH"Streptococcus
@MYGz Got that. Its Working. Thanks a lot.Sierrasiesser
G
27

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.

Galitea answered 29/12, 2016 at 6:38 Comment(4)
Is there any relation between your company and ruamel package? :)Streptococcus
@MYGz Yes, Ruamel bvba, is 100% sponsoring the development. Since I was not here promoting my own package as a solution for some problem not already involving ruamel.yaml, I didn't think about putting in a disclaimer.Galitea
Nice. I was just curious. This issue has to do with installing anaconda multiple times. He might have installed miniconda first before installing full package.Streptococcus
@MYGz I answered and then went over the comments and saw the link to the other question. Not sure why their installations gets mixed up. Writing Python programs that work on Python files, while being in some Python file containing directory or not, can be a pain wrt not loading from the standard library or some other installation in your path.Galitea
A
17

Try pip install ruamel.yaml

It works for me.

Adoptive answered 9/2, 2017 at 16:6 Comment(0)
B
11

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

Bleary answered 3/9, 2020 at 10:19 Comment(0)
S
5

Try sudo pip install ruamel_yaml

Selfabasement answered 4/2, 2017 at 9:2 Comment(0)
S
5

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.

Sylas answered 30/1, 2018 at 22:10 Comment(0)
C
3

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

Clearing answered 2/11, 2021 at 2:38 Comment(0)
B
1

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.

Boilermaker answered 18/1, 2017 at 6:3 Comment(0)
C
1

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

from ruamel import yaml

to

from ruamel_yaml as yaml
Cognation answered 18/5, 2021 at 16:28 Comment(0)
O
0

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.

Ochlocracy answered 10/4, 2020 at 19:53 Comment(0)
A
0

For python3 use

pip3 install ruamel_yaml

if pip3 not installed try at first

sudo apt install python3-pip 
Ansley answered 6/11, 2020 at 8:20 Comment(0)
F
0

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
Fauman answered 28/1, 2021 at 21:23 Comment(0)
G
0

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'
Germayne answered 2/7, 2021 at 4:50 Comment(0)
B
0

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

 pip install --ignore-installed ruamel_yaml==0.17.4
Birdie answered 15/7, 2021 at 10:48 Comment(0)
P
0

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.

Pounce answered 10/2, 2023 at 21:51 Comment(2)
This does not really answer the question. If you have a different question, you can ask it by clicking Ask Question. To get notified when this question gets new answers, you can follow this question. Once you have enough reputation, you can also add a bounty to draw more attention to this question. - From ReviewGathers
This answer sounds like it should probably be a comment. And probably reduced to simply the paragraph starting "I have a feeling". Answers like "These are just ideas, I'm too inexperienced at this stage to offer much more than to share what happened" are not particularly helpful to anyone. I'm sure you'd be frustrated to get that as an answer.Quinn
I
0

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.

Isosteric answered 25/6, 2023 at 9:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.