Conda Colab 错误收集包元数据 (current_repodata.json):失败 InvalidVersionSpec:无效版本“4.19.112+”:空版本组件

Conda Colab Error Collecting package metadata (current_repodata.json): failed InvalidVersionSpec: Invalid version '4.19.112+':empty version component

浏览器:GoogleChrome最新

我按照这篇 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")

在classVersionOrder__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 class 处理此语法的错误。我建议将此解决方案作为快速修复,以避免对两个文件产生副作用。

如何在 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')