Linux使用python3.8运行脚本时,出现如下报错:
pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: ‘0.23ubuntu1’ (package: distro-info)
报错提示
Traceback (most recent call last):
File “CaptureHDRPointCloud.py”, line 5, in
from XXX import Device
File “/home/XXX_XXX_sdk/.local/lib/python3.8/site-packages/XXX/init.py”, line 3, in
version = XXX._version.get_version(name) # pylint: disable=protected-access
File “/home/XXX_XXX_sdk/.local/lib/python3.8/site-packages/XXX/_version.py”, line 16, in get_version
return get_distribution(module_name).version
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 514, in get_distribution
dist = get_provider(dist)
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 386, in get_provider
return working_set.find(moduleOrReq) or require(str(moduleOrReq))[0]
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 956, in require
needed = self.resolve(parse_requirements(requirements))
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 815, in resolve
dist = self._resolve_dist(
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 844, in _resolve_dist
env = Environment(self.entries)
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 1044, in init
self.scan(search_path)
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 1077, in scan
self.add(dist)
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 1096, in add
dists.sort(key=operator.attrgetter(‘hashcmp’), reverse=True)
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 2631, in hashcmp
self.parsed_version,
File “/usr/local/lib/python3.8/dist-packages/pkg_resources/init.py”, line 2685, in parsed_version
raise packaging.version.InvalidVersion(f"{str(ex)} {info}") from None
pkg_resources.extern.packaging.version.InvalidVersion: Invalid version: ‘0.23ubuntu1’ (package: distro-info)
解决方案
此报错是由于setuptools
版本过高导致的,原则上python3.8的允许的setuptools版本<66.0.0
。
需要卸载原先的setuptools:
pip3.8 uninstall setuptools
再执行:
pip3.8 install setuptools==49.2.1
再运行您的程序就可以解决了。
如果对您有帮助,点赞、关注、收藏 !
(关注“测试开发自动化” 弓中皓,获取更多学习内容)