错误不会消失,即使 deleting/commenting 故障线
Error wont dissapear, even when deleting/commenting the faulty lines
我正在 Windows 10 上的虚拟机上使用 Linux Ubuntu。
我已经从 dms_tools
下载了一个 IPython 笔记本
现在,当我尝试 运行 代码的某些部分时,出现以下错误:
/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'
因为我不知道,很想解决这个问题,所以我决定编辑这个 version.py 文件(也许不是那么聪明,但我不知道还能做什么...)
我只是决定每次评论错误的行和 return 0。
奇怪的是,我仍然在评论中得到相同的错误提示:
/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'
现在我测试了如果我只添加一些空的新行会发生什么,错误看起来像这样
(指向同一条线,那里什么都没有):
/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'
我无法解释这里发生的事情,我希望有人知道。
完整的回溯是:
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'
首先,错误TypeError: '<' not supported between instances of 'str' and 'int'
意味着您在条件检查中使用的操作数之一是字符串数据类型,另一个是整数数据类型。
您可以使用 type() 函数检查什么是什么。
接下来您可以使用 mv 命令重命名文件,然后 运行 再次使用:
python <filename.py>
简而言之:您正在尝试比较两种不同的数据类型。
如果您确定两个值都是数字,则可以在比较之前转换该值:
if int(self.version) < int(other.version):
问题出在您的 fastq-dump 版本上。查看从 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))
关于fastq-dump --version
的输出有一个假设,即在输出版本之前有一个:
。 2.11 的情况并非如此,子进程调用的结果是:
>>> (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']
此字符串随后用于进一步的版本比较,distutils
抱怨无法将其与 fastq_dump_minversion
中保存的版本 2.8
进行比较。
解决这个问题的最简单方法是使用另一个版本的 sra 工具包。版本 2.9 应该可以工作,因为版本输出似乎符合预期:
>>> (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']
附加信息
为什么更改 lib/python3.7/distutils/version.py
不起作用? lib/python3.7/distutils/__pycache__
中有一个预编译文件正在被读取,或者是实际的 lib/python3.7/distutils/version.py
。如果你编辑 version.py
,你应该删除 __pycache__
目录中的相应文件。不过请注意,我强烈建议不要弄乱这些文件,因为如果您不知道自己在做什么,很容易破坏您的python。
P.S.
这应该在 dms_tools
版本 2.6.11
中得到修复
我正在 Windows 10 上的虚拟机上使用 Linux Ubuntu。
我已经从 dms_tools
下载了一个 IPython 笔记本现在,当我尝试 运行 代码的某些部分时,出现以下错误:
/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'
因为我不知道,很想解决这个问题,所以我决定编辑这个 version.py 文件(也许不是那么聪明,但我不知道还能做什么...)
我只是决定每次评论错误的行和 return 0。
奇怪的是,我仍然在评论中得到相同的错误提示:
/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'
现在我测试了如果我只添加一些空的新行会发生什么,错误看起来像这样 (指向同一条线,那里什么都没有):
/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'
我无法解释这里发生的事情,我希望有人知道。
完整的回溯是:
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'
首先,错误TypeError: '<' not supported between instances of 'str' and 'int'
意味着您在条件检查中使用的操作数之一是字符串数据类型,另一个是整数数据类型。
您可以使用 type() 函数检查什么是什么。
接下来您可以使用 mv 命令重命名文件,然后 运行 再次使用:
python <filename.py>
简而言之:您正在尝试比较两种不同的数据类型。 如果您确定两个值都是数字,则可以在比较之前转换该值:
if int(self.version) < int(other.version):
问题出在您的 fastq-dump 版本上。查看从 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))
关于fastq-dump --version
的输出有一个假设,即在输出版本之前有一个:
。 2.11 的情况并非如此,子进程调用的结果是:
>>> (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']
此字符串随后用于进一步的版本比较,distutils
抱怨无法将其与 fastq_dump_minversion
中保存的版本 2.8
进行比较。
解决这个问题的最简单方法是使用另一个版本的 sra 工具包。版本 2.9 应该可以工作,因为版本输出似乎符合预期:
>>> (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']
附加信息
为什么更改 lib/python3.7/distutils/version.py
不起作用? lib/python3.7/distutils/__pycache__
中有一个预编译文件正在被读取,或者是实际的 lib/python3.7/distutils/version.py
。如果你编辑 version.py
,你应该删除 __pycache__
目录中的相应文件。不过请注意,我强烈建议不要弄乱这些文件,因为如果您不知道自己在做什么,很容易破坏您的python。
P.S.
这应该在 dms_tools
版本 2.6.11