How to set GPU preferences remotely?

EDIT: My main goal is to set GPU preferences for cycles on a headless server in my basement. Originally, every time I asked how to do this from command line, people would tell me to “Just use VNC,” which wouldn’t work either which is why I started posting here.

I am using tightVNC to connect to an Ubuntu 18.04 server.

When I try to start blender, I get the following error in the command line:

Xlib: extension “XInputExtension” missing on display “:1”.
Read prefs: /home/shard1/.config/blender/2.79/config/userpref.blend
/build/blender-UBljLx/blender-2.79.b+dfsg0/intern/ghost/intern/GHOST_WindowX11.cpp:198: X11 glXQueryVersion() failed, verify working openGL system!
initial window could not find the GLX extension
Writing: /tmp/blender.crash.txt
Segmentation fault (core dumped)

I then tried to run “sudo xinit &” and “/opt/VIrtualGL/bin/vglrun blender” but got the following error:

Xlib: extension “XInputExtension” missing on display “:1”.
Read prefs: /home/shard1/.config/blender/2.79/config/userpref.blend
[VGL] ERROR: Could not open display :0.

I’m like 7 problems deep into the trouble shooting rabbit hole atm so any help would be greatly apreciated.

Not really familiar with this setup, but base on the listed errors there are some solutions (or breadcrumbs to solutions) here

Based on the missing OpenGL, you might need some libraries installed, like the mesa libraries. What does the crash report say at /temp/blender.crash.txt

Emulated drivers wont go well with Blender. If you have a desktop running (that already is running on real graphics card) already use Nomachine instead of Vnc.

You did not tell how you are running the Ubuntu server. Is it a VPS or a real desktop, headless etc?

If you have no real desktop or no real graphics card (like a VirtualBox, or Qemu) then you can try putting opengl dlls in the folder on Windows but you wont get good performance.

Find the opengl dll ffrom this release and put where the binary is. In any case these will just let you start Blender but you wont be able to do advanced stuff, if you are lucky.

For Windows

For Linux
try installing Mesa drivers

Another thing you can try is to use Virtualbox on Ubuntu to run a version of Windows/Linux with their Virtualbox opengl drivers

The last resort is to run the command line version of Blender on your server and use Python to control it.

The machine is an old computer that I have in my basement with a GTX 970. The only reason I need to open Blender is because I need to set the CUDA device in the preferences which I can’t do from SSH.

The crash log says:

> # Blender 2.79 (sub 0), Unknown revision
> # backtrace
> blender(BLI_system_backtrace+0x33) [0x5605f165e833]
> blender(+0x103fee3) [0x5605f0be8ee3]
> /lib/x86_64-linux-gnu/ [0x7f50e40aef20]
> blender(GHOST_GetDPIHint+0) [0x5605f167bc10]
> blender(WM_window_set_dpi+0x12) [0x5605f0c09362]
> blender(ED_screen_refresh+0xe9) [0x5605f0f005c9]
> blender(ED_screens_initialize+0x2b) [0x5605f0f00c0b]
> blender(WM_check+0x68) [0x5605f0be99e8]
> blender(wm_homefile_read+0x3c9) [0x5605f0bf7079]
> blender(WM_init+0x14b) [0x5605f0bf975b]
> blender(main+0x21a) [0x5605f0ba8b1a]
> /lib/x86_64-linux-gnu/ [0x7f50e4091b97]
> blender(_start+0x2a) [0x5605f0be5b2a]

Does blender --python-console work?

If this is about rendering see if you can set the cuda in the script then render your scene via the script. I think there was a similar post recently of this kind of use.

However there might be limitations of Cuda on different systems and I am not sure how that would play out on Linux.

That’s what I was trying to do, but every-time I ask someone how to do it in python, they reply with “Just do it in VNC.”

I’ve managed to get as far as

> import bpy
> prefs = bpy.context.user_preferences.addons['cycles'].preferences
> devices = prefs.devices
> print(prefs.compute_device_type)
> for d in devices:
>         print(

Which prints the output:

AMD FX™-6350 Six-Core Processor
GeForce GTX 970 (Display)

Blender quit

and running

import bpy
bpy.context.user_preferences.addons[‘cycles’].preferences.compute_device_type = ‘CUDA’

Which returns:

> Traceback (most recent call last):
>   File "/home/shard1/", line 2, in <module>
>     bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
> TypeError: bpy_struct: item.attr = val: enum "CUDA" not found in ('NONE')
> Blender quit

I understand that last error pretty clearly, but don’t know enough about the Blender API to accurately change these values.

VNC is no help with Blender if you do not have an accelarated desktop running already, at least that has been my experience.

See this post, might be a help

@kkar that post seems really close to what I need. It “Works,” but it doesn’t list my GPU, or help me set it.

When I run

>>> import _cycles
>>> _cycles.available_devices()

I get

(('AMD FX(tm)-6350 Six-Core Processor', 'CPU', 'CPU'),)

but I still get my GPU listed when I run

(using "blender -b --python" command)

import bpy
prefs = bpy.context.user_preferences.addons['cycles'].preferences
devices = prefs.devices

for d in devices:


AMD FX™-6350 Six-Core Processor
GeForce GTX 970 (Display)

Well, when I list my devices I get Cuda devices on top of my gpu. As you see CUDA is listed as a separate entity.

(('Intel Core i7-8700K CPU @ 3.70GHz', 'CPU', 'CPU'), ('GeForce GTX 1070 (Display)', 'CUDA', 'CUDA_GeForce GTX 1070_0000:01:00'))

I think that is your issue, you might be missing your Cuda drivers. Are you using open source drivers or Nvidia drivers?

I re-installed the CUDA drivers this morning and I thought they worked, but I reinstalled them again and now I get the following output:

>>> import _cycles
>>> _cycles.available_devices()
(('AMD FX(tm)-6350 Six-Core Processor', 'CPU', 'CPU'), ('GeForce GTX 970', 'CUDA', 'CUDA_GeForce GTX 970_0000:01:00'))

Getting really close, now all I need to do is figure out how to set the preferences

Also, somewhat unrelated question: Since this thread changed from “Can’t start blender through VNC,” to “How to remotely set GPU preferences from command line,” would it be a good idea to just entirely change the title and contents of the first post?

It would have been more helpful if you revealed what you were trying to do in the beginning, we had a bit of Memento situation here.

In anycase I would say add [SOLVED] and maybe change the title for the future reference?

The issue was that Every time I asked “How do I set the preferences from python,” everyone would just tell me to “Use VNC,” which led me here.

atm I’m back to where I started, which is trying to find out how to actually set the GPU preferences through python

Yeah, not sure I see no correalation between your initial question and their answers to your question. You did a bit of tail chase unfortunately.

See this

I am guessing this is the bit you are missing

import bpy
bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'

bpy.context.user_preferences.addons['cycles'].preferences.compute_device = 'CUDA_MULTI_2'
1 Like

@kkar thank you so much, this was finally the solution.

The lines I needed were actually the following two, but it was found in the same thread you linked to.

bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
bpy.context.user_preferences.addons['cycles'].preferences.devices[0].use = True

For future reference:

  1. Check to see if Cycles can see devices by running the following from command line and seeing if it lists your devices
blender -b --python-console  #launches the blender python console
import _cycles

It should give an output like

(('AMD FX(tm)-6350 Six-Core Processor', 'CPU', 'CPU'), ('GeForce GTX 970', 'CUDA', 'CUDA_GeForce GTX 970_0000:01:00'))
  1. If your devices are not listed then install / reinstall NVidia / CUDA drivers. If your device is listed proceed to step 3

  2. In order to set your devices, run the following from the blender python console (where X is your desired CUDA device number)

bpy.context.user_preferences.addons['cycles'].preferences.compute_device_type = 'CUDA'
bpy.context.user_preferences.addons['cycles'].preferences.devices[X].use = True

This will probably be completely outdated in a couple months when 2.8 releases and I am going to have to figure this out all over again, but in the mean time I hope this helps somebody

and again, thank you @kkar for being patient and helping me through this :grinning:

1 Like

Quick update for 2.8,

bpy.context.user_preferences changed to bpy.context.preferences

instead of _cycles.available_devices() use preferences.get_devices() which will now return a 2D array / list

I’m not sure what the 2 dimensions of the array represent, but devices[0] returns something like (MY_GPU1, MY_GPU2, MY_CPU) and devices[1] only returns (MY_CPU)

so the final code would look something like this

import bpy

prefs = bpy.context.preferences.addons['cycles'].preferences
devices = prefs.get_devices()

prefs.compute_device_type = 'CUDA'
devices[0][0].use = True                           # enable first GPU
devices[0][1].use = True                           # enable second GPU / device (if you have one)

I don’t know if this is technically proper, but this is the way I ended up doing it

1 Like