终端无法打开并显示以下消息:bash:/usr/local/bin/powerline-shell:/usr/bin/python:坏解释器:没有此文件或目录

终端无法打开并显示以下消息:bash:/usr/local/bin/powerline-shell:/usr/bin/python:坏解释器:没有此文件或目录

当我今天尝试打开终端强制更新 Firefox 时,终端中出现了以下消息:

bash: /usr/local/bin/powerline-shell: /usr/bin/python: bad interpreter: No such file or directory
Ubuntu ver 22.04 lts 64 bit

现在尝试重新安装 Python 3 后,出现了以下情况

sudo apt install --reinstall python-is-python3
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 3 not upgraded.
Need to get 2,788 B of archives.
After this operation, 0 B of additional disk space will be used.
Get:1 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 python-is-python3 all 3.9.2-2 [2,788 B]
Fetched 2,788 B in 1s (4,161 B/s)             
(Reading database ... 420664 files and directories currently installed.)
Preparing to unpack .../python-is-python3_3.9.2-2_all.deb ...
Unpacking python-is-python3 (3.9.2-2) over (3.9.2-2) ...
Setting up python-is-python3 (3.9.2-2) ...
Processing triggers for man-db (2.10.2-1) ...
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 1.16.0-unknown is an invalid version and will not be supported in a future release
  warnings.warn(
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
  warnings.warn(
Traceback (most recent call last):
  File "/usr/local/bin/powerline-shell", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3267, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3241, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3279, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 573, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 891, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 777, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'powerline-shell==0.7.0' distribution was not found and is required by the application

当我关闭并重新打开终端时,显示的内容如下:

/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 1.16.0-unknown is an invalid version and will not be supported in a future release
  warnings.warn(
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 0.1.43ubuntu1 is an invalid version and will not be supported in a future release
  warnings.warn(
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:116: PkgResourcesDeprecationWarning: 1.1build1 is an invalid version and will not be supported in a future release
  warnings.warn(
Traceback (most recent call last):
  File "/usr/local/bin/powerline-shell", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3267, in <module>
    def _initialize_master_working_set():
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3241, in _call_aside
    f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 3279, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 573, in _build_master
    ws.require(__requires__)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 891, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 777, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'powerline-shell==0.7.0' distribution was not found and is required by the application

答案1

/usr/bin/python通过链接到运行以下命令来修复该问题/usr/bin/python3

sudo apt update
sudo apt install python-is-python3

解释:

旧版本的 Ubuntu 使用 Python2 作为默认版本。传统上,/usr/bin/python链接到Python3/usr/bin/python2并且大多数脚本明确/usr/bin/python3为 Python3 运行。几年前,在过渡到 Python3 之后,他们将此选项留给用户以实现向后兼容性。

在过渡后的早期版本中,有两个选项:python-is-python2python-is-python3。安装其中一个软件包都会将其各自的 Python 版本链接到/usr/bin/python。同样,这是为了确保向后兼容性。从那时起,Python2 已经变得有些过时,现在似乎python-is-python3是唯一可用的选项。如果没有此软件包,则没有符号链接,/usr/bin/python除非您手动创建一个。

这个相关问题了解更多信息。


编辑:

因此,看起来您有几个选项可以解决这个问题。

首先,运行以下命令尝试卸载 powerline-shell:

sudo pip uninstall powerline-shell

如果有效,请运行以下一系列命令在本地安装它:

/usr/bin/pip3 install --upgrade pip

现在,注销并重新登录并运行以下命令:

pip install powerline-shell

powerline-shell如果打开终端后问题仍然存在,请运行以下命令:

pip uninstall powerline-shell
git clone https://github.com/b-ryan/powerline-shell
cd powerline-shell
python setup.py install

相关内容