deep-learning - Conda Colab 收集包元数据时出错 (current_repodata.json) : failed InvalidVersionSpec: Invalid version '4.19.112+' :empty version component

标签 deep-learning anaconda conda google-colaboratory miniconda

浏览器:Google Chrome 最新版

我关注了这个Conda + Google Colab在 colab 中设置 conda 的文章几天前运行良好。

之后,我尝试设置FairMOT 通过运行这些命令

!conda create -n FairMOT --yes
!conda activate FairMOT --yes
!conda install  pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch --yes

现在,这是我收到的错误输出。

CommandNotFoundError: Your shell has not been properly configured to use 'conda deactivate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


Collecting package metadata (current_repodata.json): failed

InvalidVersionSpec: Invalid version '4.19.112+': empty version component


CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
To initialize your shell, run

    $ conda init <SHELL_NAME>

Currently supported shells are:
  - bash
  - fish
  - tcsh
  - xonsh
  - zsh
  - powershell

See 'conda init --help' for more information and options.

IMPORTANT: You may need to close and restart your shell after running 'conda init'.


Collecting package metadata (current_repodata.json): failed

InvalidVersionSpec: Invalid version '4.19.112+': empty version component

Notebook Link

最佳答案

我创建了一个有效的快速修复方法。我不推荐将此作为长期解决方案。

更改引发 InvalidVersionSpec 错误的文件内容。就我而言,这是文件 /usr/local/lib/python3.7/site-packages/conda/models/version.py。您可以使用 !conda create your_env --verbose 获取该文件的位置。 (请注意,一个文件生成异常,但另一个文件引发 InvalidVersionSpec,选择后者)。

以下是我们感兴趣的代码行:

# imports...
# Class definitions...

@with_metaclass(SingleStrArgCachingType)
class VersionOrder(object):
    # ...

    def __init__(self, vstr):
        # ...

                # The following line is raising the Exception:
                if not c:
                    raise InvalidVersionSpec(vstr, "empty version component")

VersionOrder 类的 __init__ 方法的第一行添加以下内容:

      if isinstance(vstr, str) and vstr == '4.19.112+':
          vstr = '4.19.112'

所以它看起来像这样:

# imports...
# Class definitions...

@with_metaclass(SingleStrArgCachingType)
class VersionOrder(object):
    # ...

    def __init__(self, vstr):
      if isinstance(vstr, str) and vstr == '4.19.112+': # Added code
          vstr = '4.19.112'
        # ...

                # The following line is raising the Exception:
                if not c:
                    raise InvalidVersionSpec(vstr, "empty version component")

所发生的事情基本上是从版本名称中删除+。它会产生错误,因此可能是版本规范的拼写错误,或者是 conda 的 VersionOrder 类处理此语法时的错误。我建议将此解决方案作为快速修复,以避免对两个文件产生副作用。

如何在 Colab 中轻松完成此操作

使用 cat 打印文件 /usr/local/lib/python3.7/site-packages/conda/models/version.py 的内容:

!cat /usr/local/lib/python3.7/site-packages/conda/models/version.py

使用剪贴板复制内容并将其粘贴到以魔术命令 %%file my_new_version_file.py:

开头的新代码单元中
%%file my_new_version_file.py

# Paste your clipboard here

接下来,在这个新单元中添加前面提到的代码并运行它。 这将创建一个包含单元格内容的文件 my_new_version_file.py

然后使用shutil将生成的文件移动到原始文件的路径中:

import shutil
shutil.move('my_new_version_file.py', '/usr/local/lib/python3.7/site-packages/conda/models/version.py')

关于deep-learning - Conda Colab 收集包元数据时出错 (current_repodata.json) : failed InvalidVersionSpec: Invalid version '4.19.112+' :empty version component,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66956203/

相关文章:

python - 让 TensorFlow 在 ARM Mac 上使用 GPU

machine-learning - 使用线性回归模型预测单个值时出现错误

python - 如何在 TensorFlow 中应用渐变裁剪?

machine-learning - 如何使用Knime对文本进行分类

python - 使用 Anaconda 提示将我自己的音乐采样到 OpenAI 的点唱机中

anaconda - 不同conda channel 的解释

python-3.x - 无法使 python 在 conda 环境中工作(未找到 GLIBC)

python - 尽管由 Conda 安装,但未找到 cx_Oracle

math - 为什么反向传播神经网络中必须使用非线性激活函数?

python - 不能将 PySide 与 Anaconda 一起使用