Nvidia X Server – Fix GPU Switch Error Due to Python Import

driversgraphicsnvidia-settingspython

NVIDIA PRIME PROFILES

When I try to switch to my NVIDIA this happens:

ERROR: Traceback (most recent call last):
       File "/usr/share/screen-resolution-extra/nvidia-prime.py", line 22, in
       <module>
       import sys, dbus, logging
       ImportError: No module named 'dbus'

If it helps there is another error:

** Message: PRIME: Requires offloading
** Message: PRIME: is it supported? yes

ERROR: nvidia-settings could not find the registry key file. This file should
       have been installed along with this driver at
       /usr/share/nvidia/nvidia-application-profiles-key-documentation. The
       application profiles will continue to work, but values cannot be
       prepopulated or validated, and will not be listed in the help text.
       Please see the README for possible values and descriptions.

along with lots of gtk theme parsing errors.

I have GT 635M GPU and I'm running ubuntu 16.04 LTS with gnome desktop installed.

Please help :/

EDIT 1:
I tried running

sudo apt-get install python-dbus

and got

python-dbus is already the newest version (1.2.0-3).

Switching GPU still produces the same error.

EDIT 2:
I edited the nvidia-prime.py as Sneetsher suggested. Running nvidia-settings won't print the sys.version and sys.path, but this is the output if I run the script directly.

bp@ubuntu:~$ python /usr/share/screen-resolution-extra/nvidia-prime.py 
2.7.11+ (default, Apr 17 2016, 14:00:29) 
[GCC 5.3.1 20160413]
['/usr/share/screen-resolution-extra', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client']
Usage: /usr/share/screen-resolution-extra/nvidia-prime.py nvidia|intel

Best Answer

I had the same error. I fixed it by running sudo nvidia-settings instead of nvidia-settings. This adds the necessary privileges to launch the application.