「APT」- Unable to get the locale encoding

问题描述

在执行apt-get install -y pypy-setuptools命令时,产生如下错误:

The following additional packages will be installed:
  pypy-pkg-resources
Suggested packages:
  python-setuptools-doc
The following NEW packages will be installed:
  pypy-pkg-resources pypy-setuptools
0 upgraded, 2 newly installed, 0 to remove and 1411 not upgraded.
Need to get 461 kB of archives.
After this operation, 1,903 kB of additional disk space will be used.
Get:1 http://mirrors.ustc.edu.cn/kali kali-rolling/main amd64 pypy-pkg-resources all 41.1.0-1 [154 kB]
Get:2 http://mirrors.ustc.edu.cn/kali kali-rolling/main amd64 pypy-setuptools all 41.1.0-1 [307 kB]
Fetched 461 kB in 8s (56.5 kB/s)
Fatal Python error: initfsencoding: Unable to get the locale encoding
  File "/usr/lib/python2.7/encodings/__init__.py", line 123
    raise CodecRegistryError,\
                            ^
SyntaxError: invalid syntax

Current thread 0x00007f5bf683b740 (most recent call first):
/bin/sh: line 1: 19958 Aborted                 /usr/bin/apt-listchanges --apt
E: Sub-process /usr/bin/apt-listchanges --apt || test $? -lt 10 returned an error code (1)
E: Failure running script /usr/bin/apt-listchanges --apt || test $? -lt 10

操作系统:Kali GNU/Linux Rolling

原因分析

这是我们自己的问题。在执行pypy命令时,出现No module named错误,由于不知道如何使用pypy命令,盲目设置PYTHONPATH环境变量。

实际上pypy有自己的site-packages路径,所以要单独安装pip命令,而不是修改PYTHONPATH环境变量。

解决办法

取消环境变量PYTHONPATH的设置:

unset PYTHONPATH

参考文献

Fatal Python error: Py_Initialize: Unable to get the locale encoding … SyntaxError: invalid syntax Aborted (core dumped)
All Debian package managers broken due to Python bug