Accessing bpy.context gives a '_RestrictContext' warning, how to fix this?
Short answer: don't access blendfile data when an add-on loads.



This is an intentional limitation with add-on loading which was added because it caused so many errors with inexperienced developers not properly understanding how data should be accessed, in practice it's almost never what you really want, and if for some obscure reason it is, you better not do it in an add-on (just run a script directly).

The kind of bug this caused was:


Add-on loads, sets the active scene. eg: scene = bpy.context.scene
User changes active scene or loads another blend file.
User tries to use the add-on, which starts using the previous scene.


Enabling an add-on should always give the same results no matter what Blend file you have open.

Instead, your tools should read from the context when they are activated by the user.