Asim Zahid
Asim Zahid

Reputation: 47

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

Browser: Google Chrome latest

I followed this Conda + Google Colab article to setup conda in colab which was working perfectly a few days ago.

After that, I tried to set up FairMOT By running these commands

!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

Now, This is the error output I received.

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

Upvotes: 2

Views: 849

Answers (1)

EmmanuelB
EmmanuelB

Reputation: 1437

I created a quick-fix that works. I do not recomend this as a long-term solution.

Change the contents of the file that raises the InvalidVersionSpec error. In my case this is the file /usr/local/lib/python3.7/site-packages/conda/models/version.py. You can get the location of this file for your case using !conda create your_env --verbose. (Note that one file generates the exception, but another one raises InvalidVersionSpec, go for the latter).

Following are the lines of code of our interest:

# 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")

Add the following in the first line of the __init__ method of class VersionOrder:

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

So it looks like this:

# 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")

What is happening is basically eliminating the + from the version name. It creates the error, so it might be a typo of the version spec, or a bug in handling this syntax by conda's VersionOrder class. I propose this solution as a quickfix in order to avoid side-effects on both files.

How to do this easily in Colab

Print the contents of your file /usr/local/lib/python3.7/site-packages/conda/models/version.py using cat:

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

Copy the contents using the clipboard and paste them in a new code cell that starts with the magic command %%file my_new_version_file.py:

%%file my_new_version_file.py

# Paste your clipboard here

Next, add the previously mentioned code in this new cell and run it. This will create a file my_new_version_file.py with the contents of the cell.

Then move the generated file into the path of the original one using shutil:

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

Upvotes: 3

Related Questions