如何解决错误:警告:root:无法打开文件'/etc/apt/sources.list'

Abd*_*zir 10 software-center package-management apt

wazir@wazir:~$ sudo software-properties-gtk
[sudo] password for wazir: 

(process:15506): Gtk-WARNING **: Locale not supported by C library.
    Using the fallback 'C' locale.
Cannot set locale: unsupported locale setting
WARNING:root:could not open file '/etc/apt/sources.list'

WARNING:root:could not open file '/etc/apt/sources.list'

Traceback (most recent call last):
  File "/usr/bin/software-properties-gtk", line 104, in <module>
    app = SoftwarePropertiesGtk(datadir=options.data_dir, options=options, file=file)
  File "/usr/lib/python2.7/dist-packages/softwareproperties/gtk/SoftwarePropertiesGtk.py", line 89, in __init__
    SoftwareProperties.__init__(self, options=options, datadir=datadir)
  File "/usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.py", line 97, in __init__
    self.reload_sourceslist()
  File "/usr/lib/python2.7/dist-packages/softwareproperties/SoftwareProperties.py", line 585, in reload_sourceslist
    self.distro.get_sources(self.sourceslist)    
  File "/usr/lib/python2.7/dist-packages/aptsources/distro.py", line 87, in get_sources
    raise NoDistroTemplateException("Error: could not find a "
aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template
Run Code Online (Sandbox Code Playgroud)

pet*_*ter 7

更改权限可能有效:

sudo chmod -R 0644 /etc/apt/sources.list.d/
Run Code Online (Sandbox Code Playgroud)

更新:我之前将模式设置为 0420,这在我的情况下有效,但根据评论和进一步测试,似乎 0644 是正确的。


kar*_*rel 3

  1. 您不应该使用sudoroot 身份打开图形应用程序。您应该从 Ubuntu 软件中心安装 gksu 软件包并使用该gksudo命令,而不是以sudoroot 身份打开图形应用程序。

  2. 您也不应该以 root 身份运行 software-properties-gtk。如果您需要 root 身份,应用程序将在弹出窗口中提示您使用用户密码进行身份验证。由于 software-properties-gtk 具有内置身份验证功能,因此除了作为普通用户之外,您无需运行它。

  3. 尝试正确运行 software-properties-gtk,看看是否仍然出现相同的错误。


Ubuntu 18.04 及更高版本

gksu 已在 Ubuntu 18.04 及更高版本中停止使用。要以 root 身份打开 software-properties-gtk,请运行以下命令:

sudo -H software-properties-gtk &>/dev/null  
Run Code Online (Sandbox Code Playgroud)


小智 3

在较新版本的 Ubuntu 中,sources.list 文件位于 /etc/apt/sources.list.d 中。所以你需要从official-package-repositories.list到旧的地方建立一个符号链接来解决这个问题:

sudo ln -s /etc/apt/sources.list.d/official-package-repositories.list /etc/apt/sources.list
Run Code Online (Sandbox Code Playgroud)