Importing Unicornhat library causes code not to run?

I have installed the unicorn hat library’s using the one line installer but whenever I try to import it into a python script it causes a restart.

Why is this happening and how do I stop it?

you would need to start idle with elevated privileges, from the command line:

sudo idle3

… this is because unicornhat needs root access to drive the hardware.

Everything seems to need elevated privileges

it depends what you are referring to… in term of Pimoroni libraries, no, unicornhat is in fact the only one at this point to require low level access (though it used to be true around 2 years ago for many others).

May I ask why unicorn hat requires elevated prevaledges?

It needs to write directly to the PWM hardware and DMA to allow real-time control of the WS281x ‘pixels’. Or rather that’s the job of the underlying 3rd party library (written in C - most notably to allow refined and accurate timing).