zoukankan      html  css  js  c++  java
  • NVIDIA-setting 保存失败 Unable to open X config file ‘/etc/X11/xorg.conf’ for writing

    转载:https://blog.csdn.net/ristarjia/article/details/104030677
    请去原文查看,以下主要是为了备份

    问题

    ubuntu18.04下nvidia-settings无法保存设置

    解决方法

    打开终端执行

    切记使用终端运行,才能查看出错日志,不要从开始菜单里面点击
    nvidia-settings

    点击 Save to X Configuration File 提示 Unable to open X config file ‘/etc/X11/xorg.conf’ for writing

    看终端输出

    Package xorg-server was not found in the pkg-config search path.
    Perhaps you should add the directory containing xorg-server.pc' to the PKG_CONFIG_PATH environment variable No package 'xorg-server' found Package xorg-server was not found in the pkg-config search path. Perhaps you should add the directory containing xorg-server.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'xorg-server' found
    Error accessing /usr/share/screen-resolution-extra/nvidia-polkit: No such file or directory

    ERROR: Unable to open X config file '/etc/X11/xorg.conf' for writing.

    发现没有 /usr/share/screen-resolution-extra/nvidia-polkit 文件

    1. 进入目录cd /usr/share/screen-resolution-extra && ls
    2. 发现存在nvidia-polkit.py
    3. 于是为其创建软链接,并赋予可执行权限
    sudo ln -s nvidia-polkit.py nvidia-polkit
    sudo chmod +x nvidia-polkit
    
    此时,执行Save to X Configuration File,若终端输出
    
    Package xorg-server was not found in the pkg-config search path.
    Perhaps you should add the directory containing `xorg-server.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'xorg-server' found
    Traceback (most recent call last):
      File "/usr/share/screen-resolution-extra/nvidia-polkit", line 20, in <module>
        import sys, dbus, logging, os, re
    ImportError: No module named dbus
    
    ERROR: Unable to open X config file '/etc/X11/xorg.conf' for writing.
    

    可能是因为pyhon版本问题
    切换系统默认python版本至python3

    sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100
    sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150
    sudo update-alternatives --display python
    

    可看到当前选择python3

    python - auto mode
      link best version is /usr/bin/python3
      link currently points to /usr/bin/python3
      link python is /usr/bin/python
    /usr/bin/python2 - priority 100
    /usr/bin/python3 - priority 150
    

    此时,Save to X Configuration File应执行成功

    附录:nvidia-polkit.py 内容

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    ## Copyright (C) 2001-2008 Alberto Milone <albertomilone@alice.it>
    
    ## This program is free software; you can redistribute it and/or modify
    ## it under the terms of the GNU General Public License as published by
    ## the Free Software Foundation; either version 2 of the License, or
    ## (at your option) any later version.
    
    ## This program is distributed in the hope that it will be useful,
    ## but WITHOUT ANY WARRANTY; without even the implied warranty of
    ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    ## GNU General Public License for more details.
    
    ## You should have received a copy of the GNU General Public License
    ## along with this program; if not, write to the Free Software
    ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    
    
    import sys, dbus, logging, os, re
    import optparse
    
    SERVICE_NAME   = 'com.ubuntu.ScreenResolution.Mechanism'
    OBJECT_PATH    = '/'
    INTERFACE_NAME = 'com.ubuntu.ScreenResolution.Mechanism'
    
    # Usage:
    # python /usr/share/screen-resolution-extra/nvidia-polkit.py --help
    #
    
    def get_xkit_service(widget=None):
        '''returns a dbus interface to the screenresolution mechanism'''
        service_object = dbus.SystemBus().get_object(SERVICE_NAME, OBJECT_PATH)
        service = dbus.Interface(service_object, INTERFACE_NAME)
    
        return service
    
    
    def main(options):
        exit_code = 1
        
        conf = get_xkit_service()
        if not conf:
            # dbus_cant_connect
            logging.error("cannot connect to dbus service")
            sys.exit(1)
        
        if options.filename and options.backup_filename:
            logging.debug('making backup of /etc/X11/xorg.conf to %s and writing %s to /etc/X11/xorg.conf' 
            % (options.backup_filename, options.filename))
            exit_code = conf.backupAndWriteXorgConf([options.backup_filename, options.filename])
        elif options.filename and not options.backup_filename:
            logging.debug('writing %s to /etc/X11/xorg.conf' % options.filename)
            exit_code = conf.writeXorgConf(options.filename)
        elif not options.filename and options.backup_filename:
            logging.debug('making backup of /etc/X11/xorg.conf to %s' % options.backup_filename)
            exit_code = conf.backupXorgConf(options.backup_filename)
        elif not options.filename and not options.backup_filename:
            logging.error("called with wrong arguments")
            return exit_code
    
        # All went well if exit_code == 0
        return exit_code
    
    
    if __name__ == "__main__":
        parser = optparse.OptionParser()
        parser.add_option("-w", "--write-from", dest="filename",
                          help="write xorg.conf from FILE", metavar="FILE")
        parser.add_option("-b", "--backup-to", dest="backup_filename",
                          help="backup file to FILE", metavar="FILE")
    
        (options, args) = parser.parse_args()
        
        operation_status = main(options)
    
        sys.exit(operation_status)
    
    
  • 相关阅读:
    SpringMVC-Day1 (课题有用)
    Spring-Day3
    Spring-Day2
    fix mac
    新西兰产假(陪产假)
    nz 国内航空
    英文句子
    centos7.2安装swoole扩展
    linux搭建vue框架部署环境
    微信扫描带参数二维码事件
  • 原文地址:https://www.cnblogs.com/TianyuSu/p/14853673.html
Copyright © 2011-2022 走看看