Home > Software design >  Error wont dissapear, even when deleting/commenting the faulty lines
Error wont dissapear, even when deleting/commenting the faulty lines

Time:01-25

im am using Linux Ubuntu on a Virtual machine on Windows 10.

I have downloaded a IPython Notebook from dms_tools

Now when I try to run certain parts of the code I become the following error:

/usr/lib/python3.8/distutils/version.py in _cmp(self, other)
    335         if self.version == other.version:
    336             return 0
--> 337         if self.version < other.version:
    338             return -1
    339         if self.version > other.version:

TypeError: '<' not supported between instances of 'str' and 'int'

Since I did not know, hot to solve this problem I decided to just eddit this version.py file (perhaps not so smart, but I did not know what else to do...)

I just decided to Comment the faulty lines and return 0 everytime.

Now the weird part, I still get the same error pointing on the comments:

 /usr/lib/python3.8/distutils/version.py in _cmp(self, other)
        335         # if self.version == other.version:
        336         #     return 0
    --> 337         # if self.version < other.version:
        338         #     return -1
        339         # if self.version > other.version:

TypeError: '<' not supported between instances of 'str' and 'int'

Now I tested what would happen if I just added some empty new lines and the error looks like this (pointing at the same line, where nothing even is):

  /usr/lib/python3.8/distutils/version.py in _cmp(self, other)
        335         
        336           
    --> 337         
        338             
        339         

    TypeError: '<' not supported between instances of 'str' and 'int'

I just can not explain what is happening here and I hope someone has an idea.

The complete Traceback is:

TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_2888/2193680867.py in <module>
      1 fastqdir = os.path.join(resultsdir, './FASTQ_files/')
      2 print("Downloading FASTQ files from the SRA...")
----> 3 dms_tools2.sra.fastqFromSRA(
      4         samples=samples,
      5         fastq_dump='/home/andreas/sratoolkit.2.11.0-ubuntu64/bin/fastq-dump',

~/.local/lib/python3.8/site-packages/dms_tools2/sra.py in fastqFromSRA(samples, fastq_dump, fastqdir, aspera, overwrite, passonly, no_downloads, ncpus)
     91                               .decode('utf-8').split(':')[-1].strip())
     92     fastq_dump_minversion = '2.8'
---> 93     if not (distutils.version.LooseVersion(fastq_dump_version) >=
     94             distutils.version.LooseVersion(fastq_dump_minversion)):
     95         raise RuntimeError("fastq-dump version {0} is installed. You need "

/usr/lib/python3.8/distutils/version.py in __ge__(self, other)
     68 
     69     def __ge__(self, other):
---> 70         c = self._cmp(other)
     71         if c is NotImplemented:
     72             return c

/usr/lib/python3.8/distutils/version.py in _cmp(self, other)
    335         if self.version == other.version:
    336             return 0
--> 337         if self.version < other.version:
    338             return -1
    339         if self.version > other.version:

TypeError: '<' not supported between instances of 'str' and 'int'

CodePudding user response:

The issue is with your fastq-dump version. Looking at the source code that generates the error from sra.py:

fastq_dump_version = (subprocess.check_output([fastq_dump, '--version'])
                          .decode('utf-8')
                          .replace('"fastq-dump" version', '').split(':'))
    if len(fastq_dump_version) == 1:
        fastq_dump_version = fastq_dump_version[0].strip()
    elif len(fastq_dump_version) == 2:
        fastq_dump_version = fastq_dump_version[1].strip()
    else:
        fastq_dump_version = (subprocess.check_output([fastq_dump, '--help'])
                              .decode('utf-8').split(':')[-1].strip())
    fastq_dump_minversion = '2.8'
    if not (distutils.version.LooseVersion(fastq_dump_version) >=
            distutils.version.LooseVersion(fastq_dump_minversion)):
        raise RuntimeError("fastq-dump version {0} is installed. You need "
            "at least version {1}".format(fastq_dump_version, 
            fastq_dump_minversion))

There is an assumption about the output of fastq-dump --version, i.e. that there is a : right before the version being output. This is not the case for 2.11 though and the subprocess call results in this:

>>> (subprocess.check_output(['sratoolkit.2.11.0-ubuntu64/bin/fastq-dump', '--version']).decode('utf-8').replace('"fastq-dump" version', '').split(':'))
['\n"sratoolkit.2.11.0-ubuntu64/bin/fastq-dump" version 2.11.0\n\n']

this string is then used for the version comparison further down and distutils complains about being unable to compare it to the version 2.8 saved in fastq_dump_minversion.

The easiest way to fix this is to use another version of the sra toolkit. Version 2.9 should work, as the version output seems to match the expectation:

>>> (subprocess.check_output(['sratoolkit.2.9.0-ubuntu64/bin/fastq-dump', '--version']).decode('utf-8').replace('"fastq-dump" version', '').split(':'))
['\nsratoolkit.2.9.0-ubuntu64/bin/fastq-dump ', ' 2.9.0\n\n']

Additional Info

Why did changing lib/python3.7/distutils/version.py not do the trick? There is a precompiled file in lib/python3.7/distutils/__pycache__ that is being read instead or the actual lib/python3.7/distutils/version.py. If you edit version.py, you should delete the coresponding file in the __pycache__ dir. Note though, that I strongly recommend to not mess with these files, as you can easily break your python if you don't know what you are doing.

CodePudding user response:

First of all, the error TypeError: '<' not supported between instances of 'str' and 'int' means that one of the operands you are using in condition checking is string data type and another is integer data type.

You can check what's what by using type() function.

Next what you can do is rename the file using mv command and run again using:

python <filename.py>

CodePudding user response:

In short: you are trying to compare two different data types. If you're sure that both values are number, you can convert the value before compare:

if int(self.version) < int(other.version):
  •  Tags:  
  • Related