Python Conda 'ImportError: 没有名为 ruamel.yaml.comments 的模块'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41373834/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:52:24  来源:igfitidea点击:

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

pythonyamlanacondacondaruamel.yaml

提问by Nipun Garg

Conda gives error when I run any command with it.

当我用它运行任何命令时,Conda 会出错。

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

回答by Anthon

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

模块ruamel.yaml.comments通常从 加载 site-packages/ruamel/yaml/comments.py,而不是从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 pipcompatible. That although "namespaces are a honking good idea", and package namespaces have been around for many years.

Conda 似乎在正确支持命名空间 ( ruamel.)方面存在问题,我只能将其归因于(尚未)完全pip兼容。尽管“命名空间是个好主意”,但包命名空间已经存在多年。

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

假设您可以扩展“conda”安装,pip您可以尝试使用以下方法进行正常安装ruamel.yaml

 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.

我通常不会推荐这样的旧版本,但这更有可能与 conda 在内部使用的版本结合使用。

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.

另一种方法是在没有 conda 的情况下切换到使用 python 和 pip,这样你就可以使用 PyPI 的最新版本的软件。

回答by Nicholas Luo

Try pip install ruamel.yaml

尝试 pip install ruamel.yaml

It works for me.

这个对我有用。

回答by Sergei

Try sudo pip install ruamel_yaml

尝试 sudo pip install ruamel_yaml

回答by spacetyper

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:

上面的答案对我不起作用。我必须按照此处的 conda 文档中的说明重新安装核心 conda 组件。复制粘贴如下:

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:

问题:我的 conda 坏了,我想在不破坏当前安装的情况下修复它 我收到一个 conda 错误并想重新安装 Miniconda 来修复它,但是当我尝试时,它给了我 Miniconda(或 Anaconda)已经存在的错误安装,不会让我继续。我想强制安装。

解决方案:使用 -f(强制)选项安装 Miniconda,使用 force 或 -f 选项从 Miniconda 下载页面下载并安装适合您的计算机操作系统的 Miniconda,如下所示:

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.

注意:为您的操作系统替换相应的文件名和版本。

注意:确保您安装到与现有安装相同的安装位置,以便它覆盖核心 conda 文件并且不会在新文件夹中安装重复文件。

回答by user612161

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.

将点更改为下划线对我有用......我希望它对你有用。

回答by JAG2024

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 -rfminiconda3 in my home directory, fwiw.
  2. Reinstalled conda using data camp's tutorial.
  1. 在我的主目录 fwiw 中卸载 conda(我使用了这个堆栈溢出解决方案)和rm -rfminiconda3。
  2. 使用data camp 的教程重新安装了 conda 。

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

经过大量的头部撞击后,没有其他解决方案对我有用。